有些时候,可能实际工作中需要同时使用多个装饰器,具体怎么用,见代码:
#basic5.py def auth1(func): def inner(): print ‘before 1‘ func() print ‘after 1‘ return inner def auth2(func): def inner(): print ‘before 2‘ func() print ‘after 2‘ return inner @auth2 @auth1 def f1(): print ‘f1‘
执行部分:
#b5.py #coding:utf-8 import basic5 basic5.f1()
执行结果:
#python b5.py before 2 before 1 f1 after 1 after 2
时间: 2024-10-24 16:12:39