Python __getattr__ __getattribute__
来源:互联网 发布:qt保存数据到文件 编辑:程序博客网 时间:2024/06/05 02:11
当调用对象属性时, Python会自动调用 getattribute, 当getattribute找不到属性时 会调用getattr
比如 a.dict 相当于执行了 a.getattribute(‘dict‘) 如果我们在重载getattribute中又调用dict的话,会无限递归
`class C(object):
def setattr(self, name, value):
print “setattr called:”, name, value
object.setattr(self, name, value)
def __getattr__(self, name): print "__getattr__ called:", name def __getattribute__(self, name): print "__getattribute__ called:",name return object.__getattribute__(self, name)
c = C()
c.x = “foo”`
0 0
- python __get__ __getattr__ __getattribute__
- python:__getattr__() 和 __getattribute__()
- python __getattr__和__getattribute__
- Python __getattr__ __getattribute__
- Python __getattr__ __getattribute__ __setattr__
- Python----__getattribute__, __getattr__
- python __setattr__, __getattr__, __delattr__,__getattribute__
- Python笔记:getattr,__getattr__,__getattribute__
- Python __getattribute__ vs __getattr__ 浅谈
- Python __getattribute__、__getattr__、__get__总结
- python中__get__,__getattr__,__getattribute__的区别
- python中__get__,__getattr__,__getattribute__的区别
- python魔法方法:__getattr__,__setattr__,__getattribute__
- python(第五天):__getattr__ 和 __getattribute__
- python魔法方法:__getattr__,__setattr__,__getattribute__
- python __getattribute__ 和 __getattr__的区别
- python中__getattr__,__setattr__,__getattribute__的区别
- python中__get__,__getattr__,__getattribute__的区别
- nyoj 1022 合纵连横(经典并查集=---删点操作)
- linux qt 打包安装程序
- windows UI自动化测试
- freemarker.properties的属性文件的配置说明
- iOS性能优化 instruments
- Python __getattr__ __getattribute__
- keras中查看各类版本号
- Hibernate 入门------简单的CRUD
- leetcode56. Merge Intervals
- mysql 5.7新数据库sys解析
- bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml
- TensorFlow 图像数据预处理及可视化
- 导入ssh项目到myeclipse(最新最详细)
- Android PopupWindow类