老男孩的装饰器讲解,非常精彩.

import time
def timer(func):
def deco():
start_time=time.time()
func()
stop_time=time.time()
print ('the func run time is %s'%(stop_time-start_time))
return deco
@timer #这部等价于 test1=timer(test1)
def test1():
time.sleep(3)
print ('in the test1')
test1()

posted on 2018-01-06 19:54  张博的博客  阅读(124)  评论(0编辑  收藏  举报

导航