Python property不存在时调用getProperty函数
来源:互联网 发布:直方图均衡化算法 编辑:程序博客网 时间:2024/04/29 19:27
写了一个检测方法是否存在的基类,用于动态获取属性
BaseObject.py
# -*- coding: UTF-8 -*-from functools import wrapsclass BaseObject(object): '''基类''' def __getattr__(self, name): ''' 属性不存在时,调用子类实现的getProperty()函数''' name = "get%s" % name.capitalize()#方法名 print " BaseObject __getattr__ %s \r\n" % name print " hasattr:%s callable:%s " % (hasattr(self, name), callable(getattr(self, name))) if hasattr(self, name) and callable(getattr(self, name)): print "__getattr__ class: %s , class name:%s , property name: %s %s" % ( self.__class__, self.__class__.__name__, name, (getattr(self, name)).__name__ ) getattr(self, name)() else: raise Exception('Method %s.%s does not exist!' % (self.__class__.name, name) ) return self def dump_func_info(f): '''调试函数调用情况''' @wraps(f) def with_dump(*args, **kwargs): print f.__name__ + ' was called' return f(*args, **kwargs) return with_dump
阅读全文
0 0
- Python property不存在时调用getProperty函数
- Python __init__ 构造函数生成对象时调用关系
- xcode编译程序时调用python脚本
- MFC 关闭时调用的函数
- 当文档准备就绪时调用函数
- python 的property函数
- python property函数
- python property 函数用法
- python中的property函数
- python property函数
- python中的property函数
- Python属性函数property
- Python property() 函数
- Python中的@property和property函数
- 函数返回类时调用构造函数次数
- Learning Python : 2 . property函数
- 定义并初始化时调用拷贝构造函数
- Gallery3D中画图时调用glTranslate函数参数赋值过程
- 使用DateUtils跟DateFormatUtils处理时间日期转换
- Uva 714 (抄书问题,二分查找+贪心)
- 页面禁止滚动
- 深入理解HTTP协议、HTTP协议原理分析
- 我爱测试
- Python property不存在时调用getProperty函数
- Android Studio(as)调试总结
- 正则笔记
- c++ 多线程学习笔记(一)
- H3C-QoS
- 文章标题
- 3用于MNIST的卷积神经网络-3.7学习率与权重初始化对网络性能的影响分析
- 自旋锁、排队自旋锁、MCS锁、CLH锁
- I2C协议