def decorate_log(decorate_arg,*args,**kwargs): # 存放装饰器参数
def decorate_wrapper(func,*args,**kwargs): # 存放函数名
def wrapper(text,*args,**kwargs): # 存放函数参数
start_time = time.clock()
func(text)
decorate_text = decorate_arg + '+' + text
print('decorate text: ' + decorate_text)
print('function %s() spend time: %d'% (func.__name__,int((time.clock()-start_time))))
# return decorate_text
return wrapper
return decorate_wrapper
@decorate_log('test')
def func(text):
time.sleep(3)
print('func text: '+ text)
func('ttt')
func('eee')
Advanced Uses of Python Decorators
https://www.codementor.io/sheena/advanced-use-python-decorators-class-function-du107nxsv