30 裝飾器終極版本(進階)
阿新 • • 發佈:2018-11-06
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()