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

python 对一个函数应用多个装饰器

2017-09-08 10:12 459 查看
下面的例子展示了对一个函数应用多个装饰器,可以加多个断点,在debug模式下,查看程序的运行轨迹。。。

[python] view
plain copy

#!/usr/bin/env python  

#coding:utf-8  

def decorator1(func):  

    def wrapper():  

        print 'hello python 之前'  

        func()  

    return wrapper  

  

def decorator2(func):  

    def wrapper():  

        func()  

        print 'hello python 之后'  

    return wrapper  

 

@decorator1  

@decorator2  

def test():  

    print 'hello python!'  

  

test()  

运行结果:

hello python 之前

hello python!

hello python 之后

关于python装饰器的更多介绍,请参考:

1》Python装饰器学习(九步入门)

2》 Python装饰器与面向切面编程
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐