多重装饰器

2020-08-19  本文已影响0人  雨景江水

一.各种装饰器回顾:
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

上一篇 下一篇

猜你喜欢

热点阅读