import time
FLAGE = False
def timmer_out(flag):
def timmer(func):
def inner(*args,**kwargs):
if flag:
start = time.time()
ret = func(*args,**kwargs)
end = time.time()
print(end-start)
return ret
else:
ret = func(*args, **kwargs)
return ret
return inner
return timmer
@timmer_out(FLAGE)
def wahaha():
time.sleep(0.1)
print("wahhhhahahahahh")
@timmer_out(FLAGE)
def erguotou():
time.sleep(0.1)
print("erguotoutoutotuou")
wahaha()
erguotou()
30 装饰器终极版本(进阶)
猜你喜欢
转载自www.cnblogs.com/wssaried/p/9916305.html
今日推荐
周排行