python -- getattr
来源:互联网 发布:勇敢的心德莱厄斯淘宝 编辑:程序博客网 时间:2024/04/29 07:27
https://docs.python.org/2/library/functions.html?highlight=getattr#getattr
- getattr(object,name[,default])
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 thevalue of that attribute. For example,getattr(x,'foobar') is equivalent tox.foobar. If the named attribute does not exist,default is returned ifprovided, otherwiseAttributeError is raised.
=============================================================================================
def __init__(self, name=None, **kwargs): if name is not None: self.name = name elif not getattr(self, 'name', None): raise ValueError("%s must have a name" % type(self).__name__) self.__dict__.update(kwargs) if not hasattr(self, 'start_urls'): self.start_urls = []
if not getattr(str, '__invalid__', 'string'):
print 'No' # 不打印No
if not getattr(str, '__invalid__', None):
print 'No' # 打印No
x = not getattr(str, 'string', None) # x = True
y = not getattr(str, 'string', 'string') # y = False
=============================================================================================
- hasattr(object,name)
The arguments are an object and a string. The result is True if the stringis the name of one of the object’s attributes,False if not. (This isimplemented by callinggetattr(object, name) and seeing whether it raises anexception or not.)
- python getattr()
- python -- getattr
- python getattr
- python getattr()
- Python的getattr函数
- python: 理解 __getattr__, getattr ,
- python: 理解 __getattr__, getattr ,
- Python的getattr()
- Python getattr实际使用
- Python:getattr() 和__getattr__()
- python: 理解 __getattr__, getattr ,
- Python’s getattr function
- python-setattr,getattr,getattribute
- python 内置函数getattr
- Python getattr()方法
- python getattr setattr
- Python的hasattr、getattr
- 神奇的getattr - Python
- [LeetCode]String to Integer (atoi)
- 模拟思想和hash_set
- FTP协议的分析和扩展
- Python拼接用户名和密码小程序
- poj 2868 Who Gets the Most Candies?
- python -- getattr
- MetaModel-full-1.1.8.jar包下载
- linux的lsof命令
- hadoop学习;自定义Input/OutputFormat;类引用mapreduce.mapper;三种模式
- SQL Server2005单独附加MDF文件出现1813错误
- win7 64位下安装selenium
- [转]项目经理应该把30%的时间用在编程上
- matlab目录操作
- Paxos在大型系统中常见的应用场景