装饰器
例:
import datetime
import time
def logger3(duration=3):
def _logger3(fn):
def inner(*args,**kwargs):
start = datetime.datetime.now()
ret = fn(*args,**kwargs)
delta = (datetime.datetime.now() - start).total_seconds()
if delta > duration:
print(fn.__name__,'{:.4f}'.format(delta) )
else:
print('good')
return ret
return inner
return _logger3
@logger3(0.1)
def add3(x,y):
time.sleep(1)
return x + y
print(add3(3,4))