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()

结果展示:

 



posted @ 2024-07-25 21:36  枫叶少年  阅读(4)  评论(0编辑  收藏  举报