def deco1(func1): def wrapper1(*args,**kwargs): print("运行deco1_wrapper1") res1=func1(*args,**kwargs) return res1 return wrapper1 def deco2(func2): def wrapper2(*args,**kwargs): print("运行deco2_wrapper2") res2=func2(*args,**kwargs) return res2 return wrapper2 def deco3(x): def outter3(func3): def wrapper3(*args,**kwargs): print("运行deco3_wrapper3") res3=func3(*args,**kwargs) return res3 return wrapper3 return outter3 @deco1 #index=deco1(wrapper2的内存地址) ===> index=wrapper1 的内存地址 @deco2 #index=deco2(wrapper3的内存地址) ===> index=wrapper2 的内存地址 @deco3(1) #===>@outter3===> index=outter3(index) ===>index=wrapper3 的内存地址 def index(x,y): print("from index %s,%s" %(x,y)) index(1,2)
'''执行顺序是自上而下的,即wrapper1 --> wrapper2--> wrapper3'''
/usr/local/bin/python3.8 /Users/futantan/PycharmProjects/S14/函数的学习/迭代器.py 运行deco1_wrapper1 运行deco2_wrapper2 运行deco3_wrapper3 from index 1,2 Process finished with exit code 0
标签:wrapper3,index,叠加,return,wrapper2,python,wrapper1,--,def From: https://www.cnblogs.com/clairedandan/p/18143577