老男孩的装饰器讲解,非常精彩.
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()