目錄html
python寫的程序多了,發現不少方法,不少小工具能夠複用,記錄起來,作成目錄,或者直接貼代碼python
class Singleton: """單例""" _instance_lock = Lock() # 新建實例用到的鎖 def __init__(self, hub_url): pass def __new__(cls, *args, **kwargs): if not hasattr(Singleton, "_instance"): with Singleton._instance_lock: if not hasattr(Singleton, "_instance"): Singleton._instance = object.__new__(cls) Singleton._instance.hub_url = args[0] # 屬性賦值什麼的,好像只能放在這 return Singleton._instance
Loggingmysql
計時裝飾器git
def timer(func): @functools.wraps(func) def wrapper(*args, **kwargs): start = time.time() print('開始時間: {}'.format(start)) result = func(*args, **kwargs) ended = time.time() print('結束時間: {}, 耗時: {}'.format(ended, ended-start)) return result return wrapper
增刪查改(待更)redis
(待更)sql
解析庫,(待更)docker