标签:
装饰器:本质是一个函数,就是为其他函数添加附件功能
特性:1.不能修改被装饰函数的源代码
2.不能修改被装饰函数的调用方式
#装饰器
import time
def deco(func):
def gao(*args,**kwargs):
start_time=time.time()
func(*args,**kwargs)
stop_time=time.time()
print("in the func %s" %(stop_time-start_time))
return gao
@deco
def test():
time.sleep(1)
print("in the test")
def test2(name): #test2=deco(test2)=gao
time.sleep(1)
print("in the test2",name)
test()
test2("alex")
标签:
原文地址:http://www.cnblogs.com/xuehuahongmei/p/5958480.html