python 装饰器 三 (带有参数的装饰器)
2015-07-01 01:26
477 查看
#接受装饰器的参数def deco_arg(deco_arg): #接受函数 此列为func1 def deco_func(*argv,**kwag): #接受函数的方法 此列为 a b def _deco_func(*argv,**kwarg): print "before -------执行函数前" print "%s -------打印装饰器的参数"% deco_arg ret = deco_func(*argv,**kwarg) print "after -------执行函数后" return ret return _deco_func return deco_func@deco_arg('我是装饰器的参数')def func1(a,b): print a print b return "ok"func1('xixi','haha')'''执行结果before -------执行函数前我是装饰器的参数 -------打印装饰器的参数after -------执行函数后'''
相关文章推荐
- python 装饰器 二 (装饰带参数的函数)
- python获取一组汉字拼音首字母的方法
- python实现的希尔排序算法实例
- python选择排序算法实例总结
- python保存字符串到文件的方法
- 在Python中marshal对象序列化的相关知识
- Python笔记:urllib2模块
- Python笔记:urllib模块
- python删除N天前文件
- python numpy矩阵和数组的转换
- Think In Python Exercise
- python 简单图像处理(13)
- Python学习之二【初学Python】
- 最近在学习python
- python装饰器
- python 优秀文章索引
- python编程之键盘响应
- Python学习十四:filter()
- Python图像处理(12):贝叶斯分类器
- python脚本