Python实现对一个函数应用多个装饰器的方法示例
作者:快递小可 时间:2022-01-23 17:30:22
本文实例讲述了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. Python装饰器学习(九步入门)
2. Python装饰器与面向切面编程
希望本文所述对大家Python程序设计有所帮助。
来源:http://blog.csdn.net/sxingming/article/details/52433019
标签:Python,函数,装饰器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中的十大图像处理工具(小结)
2021-02-04 09:17:51
![](https://img.aspxhome.com/file/2023/2/82612_0s.jpg)
新功能的帮助与破坏
2010-01-17 10:15:00
![](https://img.aspxhome.com/file/UploadPic/20101/17/bai_photo-14s.png)
Python实现XML文件解析的示例代码
2022-02-24 11:03:43
获取CSDN文章内容并转换为markdown文本的python
2021-04-05 08:32:15
![](https://img.aspxhome.com/file/2023/2/66382_0s.png)
python格式化字符串的实战教程(使用占位符、format方法)
2023-02-01 22:20:21
![](https://img.aspxhome.com/file/2023/3/75353_0s.png)
Python之requests的使用(二)
2021-10-30 16:44:51
python获取指定时间段内特定规律的日期列表
2021-02-09 02:16:25
![](https://img.aspxhome.com/file/2023/0/76930_0s.png)
PHP用mysql数据库存储session的代码
2023-09-05 00:44:50
python逆向微信指数爬取实现步骤
2022-03-31 03:36:48
![](https://img.aspxhome.com/file/2023/2/81602_0s.jpg)
windows下安装python的C扩展编译环境(解决Unable to find vcvarsall.bat)
2022-03-22 02:31:42
![](https://img.aspxhome.com/file/2023/2/78552_0s.png)
SQL Server中使用DTS设计器进行数据转移
2009-01-08 16:15:00
python函数参数(必须参数、可变参数、关键字参数)
2023-09-17 07:54:28
python 子类调用父类的构造函数实例
2023-05-27 22:33:37
![](https://img.aspxhome.com/file/2023/5/70135_0s.jpg)
Python数据结构之二叉排序树的定义、查找、插入、构造、删除
2022-03-03 08:19:51
![](https://img.aspxhome.com/file/2023/4/78804_0s.jpg)
python开发的小球完全弹性碰撞游戏代码
2023-11-01 07:47:11
![](https://img.aspxhome.com/file/2023/5/81615_0s.png)
解决django接口无法通过ip进行访问的问题
2023-09-15 14:07:27
![](https://img.aspxhome.com/file/2023/6/62266_0s.jpg)
python的绘图工具matplotlib使用实例
2023-10-09 13:23:28
![](https://img.aspxhome.com/file/2023/6/62896_0s.png)
PHP PDOStatement::nextRowset讲解
2023-06-06 07:18:28
GoLang调用链可视化go-callvis使用介绍
2023-07-16 06:39:59
![](https://img.aspxhome.com/file/2023/5/89025_0s.png)
PHP中quotemeta()函数的用法讲解
2023-06-08 04:04:24
![](https://img.aspxhome.com/file/2023/7/55377_0s.png)