多层装饰器的调用及执行顺序
1 def wrapper1(func): #func= get_inter2 2 def get_inter1(*args,**kwargs): 3 print('get1——前') 4 f=func(*args,**kwargs) #调用get_inter2() 5 print('get1——后') 6 return f 7 return get_inter1 8 9 def wrapper2(func): #func=get_inter3 10 def get_inter2(*args,**kwargs): 11 print('get2——前') 12 f=func(*args,**kwargs) #调用show 被执行 13 print('get2——后') 14 return f 15 return get_inter2 16 17 def wrapper3(func): #func=show 18 def get_inter3(*args,**kwargs): 19 print('get3——前') 20 f=func(*args,**kwargs) #调用show 被执行 21 print('get3——后') 22 return f 23 return get_inter3 24 25 @wrapper1 #show=wrapper1(show) 相当于wrpper1(get_inter2) ---->return get_inter1 #show在执行完上述三步后已经被赋值>>>get_inter1 26 @wrapper2 #show=wraaper2(show) 相当于wrapper2(get_inter3) ==get_inter2 27 @wrapper3 #show=wrapper3(show) ==get_inter3 28 def show(): 29 print('hello python') 30 return 'Ojbk' 31 re=show() #调用get_inter1() 32 print(re) #打印'Ojbk' 33 34 #装饰器的加载顺序是 wrapper3-->wrapper2-->wrapper1