[英] How to know if an object has an attribute in Python
在Python中有没有一种方法来确定对象是否具有某些属性?例如:
>>> a = SomeClass()
>>> a.someProperty = value
>>> a.property
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: SomeClass instance has no attribute 'property'
在使用a
之前,如何判断它是否具有属性property
?