您的位置:首页 > 编程语言 > Python开发

python学习系列之python装饰器基础(5)---多装饰器的使用

2015-11-30 17:37 731 查看
有些时候,可能实际工作中需要同时使用多个装饰器,具体怎么用,见代码:
#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


本文出自 “苦咖啡's运维之路” 博客,请务必保留此出处http://alsww.blog.51cto.com/2001924/1718270
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: