一.各种装饰器回顾:
https://www.bilibili.com/video/av796278169?p=3
二.
多重装饰器的使用顺序为:
装饰时顺序为从内到外,执行时从外到内
详解:https://blog.csdn.net/got_be_better/article/details/82989247
三.
def decorator1(func):
print('before_decorated_1')
def wrapper1():
print('execute_decorator_1')
return func()
return wrapper1
def decorator2(func):
print('before_decorated_2')
def wrapper2():
print('execute_decorator_2')
return func()
return wrapper2
@decorator1
@decorator2
def test():
print('test result')
test()
:
before_decorated_2
before_decorated_1
execute_decorator_1
execute_decorator_2
test result
网友评论