如何知道对象在Python中是否具有属性
发布于 2021-02-02 23:14:33
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之前,如何知道该属性是否存在?
关注者
0
被浏览
81
1 个回答