python 装饰器执行顺序的代码示例
def decoratorA(func):
print(33)
def wrapperA():
print("Entering A")
print(func())
print("Exiting A")
print(44)
return wrapperA
def decoratorB(func):
print(11)
def wrapperB():
print("Entering B")
func()
print("Exiting B")
print(22)
return wrapperB
@decoratorB
@decoratorA
def my_function():
print("Inside my_function")
return 34
# 调用被装饰器包装的函数
my_function()
结果展示: