复习装饰器
review——decorator,参数传递:import time
def timer(argv):
def out_wraper(func):
def wraper(a, b):
print('In the %s' % func)
start_time = time.time()
time.sleep(2)
func(a, b)
stop_time = time.time()
print('the running timeof %s is:%s' %(argv,(stop_time - start_time)))
return wraper
return out_wraper
@timer('add')
def add(a, b):
print(a + b)
@timer('sub')
def sub(a, b):
print(a - b)
add(3, 5)
sub(8, 3)
页:
[1]