水景,幻影少年第二季,印宗强力胶囊
本文实例讲述了Python实现对一个函数应用多个装饰器的方法。分享给大家供大家参考,具体如下:
下面的例子展示了对一个函数应用多个装饰器,可以加多个断点,在debug模式下,查看程序的运行轨迹。。。
#!/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.
2.
更多关于Python相关内容可查看本站专题:《》、《》、《》、《》及《》
希望本文所述对大家Python程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论