Python入门:装饰器案例1
import time
def timer(func): #timer(test1) func=test1
def deco():
star_time=time.time()
func() # run test1
stop_time=time.time()
print("the func run time is %s" %(stop_time-star_time))
return deco
@timer # test1=timer(test1)
def test1():
time.sleep(3)
print("in the test1")
@timer # test2=timer(test2)
def test2():
time.sleep(3)
print("in the test2")
test1()
test2()