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')

https://www.codementor.io/sheena/advanced-use-python-decorators-class-function-du107nxsv

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2021-08-20
  • 2021-08-05
  • 2022-12-23
猜你喜欢
  • 2021-06-02
  • 2022-12-23
  • 2021-08-30
  • 2021-06-21
  • 2021-05-23
  • 2021-04-12
  • 2021-06-15
相关资源
相似解决方案