Python 内建函数 - getattr(object, name[, default])
2017-03-15 17:34
435 查看
Manual
直译
实例
拓展阅读
hasattr()
setattr()
直译
实例
拓展阅读
Manual
Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, ‘foobar’) is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.直译
返回object中名为name的属性值。name必须是字符串,如果字符串是对象某个属性名,结果为该属性值,例如getattr(x, ‘foobar’)等价于x.foobar。如果给定的name不存在,会根据提供的默认值进行返回,否则会引发AttributeError。实例
>>> class CSDN: def foobar(self): print('Hello CSDNer!') >>> getattr(CSDN, 'foobar') <function CSDN.foobar at 0x03944F18> >>> CSDN.foobar <function CSDN.foobar at 0x03944F18>
拓展阅读
delattr()hasattr()
setattr()
相关文章推荐
- python 中getattr(object,name,default),setattr(object,name,default),hasattr(),delattr()
- Python标准库:内置函数getattr(object, name[, default])
- Python标准库:内置函数getattr(object, name[, default])
- Python标准库:内置函数getattr(object, name[, default])
- Python 内建函数 - delattr(object, name)
- python内建函数hasattr(object, name)
- Python json序列化时default/object_hook指定函数处理
- Python 内建函数 - setattr(object, name, value)
- Python 内建函数 - hasattr(object, name)
- python文件中的__name__=='__main__'的使用及调用其他py文件中的函数方法
- python 面向对象中一些常用内建函数【getattr(), setattr(). hasattr(). delattr()...】
- python魔法函数__dict__和__getattr__的妙用
- python中 __getattr__(self,name)和__setattr__(self,name,value)的使用
- Python标准库:内置函数hasattr(object, name)
- python setattr(),getattr()函数
- python 知识点:反射 之 getattr()实现以字符串形式导入模块和执行函数
- 详解Python的hasattr() getattr() setattr() 函数使用方法
- Python的hasattr() getattr() setattr() 函数使用方法详解
- python中字典处理函数get和setdefault的区别
- python中getattr函数使用方法 getattr实现工厂模式