python装饰器
2016-04-28 17:06
134 查看
''' AOP之类装饰器 ''' #标准 def standard(class_): class_.standard=class_ print(class_.name) return class_ #非标准 def nonstandard(based_on): def concrete_decorator(class_): class_.standard=based_on print(class_.name) return class_ return concrete_decorator class Unit: factor=1.0 @classmethod def value(class_,value): if value is None: return None return value/class_.factor @classmethod def convert(class_,value): if value is None:return None return value*class_.factor @standard class INCH(Unit): """inch""" name="in" @nonstandard(INCH) class FOOT(Unit): """foot""" name='ft' factor=1/12
相关文章推荐
- Python3学习(二)-递归函数、高级特性、切片
- selenium+webdriver+python定位不到元素的原因及解决办法
- 0045 Ubuntu常用指令(与mysql,python,hadoop,spark,java ,g++,编辑器等相关)
- [LeetCode]题解(python):141-Linked List Cycle
- python log
- 如何远程调试Python代码
- 如何远程调试Python代码 推荐
- [LeetCode]题解(python):140-Word Break II
- Python 迭代器与生成器
- Python MySQL 数据库连接
- iPython的安装与简单使用
- python之高阶函数编程
- 基于车牌颜色(仅限蓝色和黄色)的车牌定位(python+opencv实现)
- Python--开始之前的铺垫
- python学习简要笔记1
- numpy.load和numpy.save
- Windows下使用gvim编写Python程序缩进的设置
- [python 2.7.5] 实现配置文件的读写
- Pyinstaller 打包python 到exe 在windows下免python环境运行python
- st3搭建python开发环境