How to know if an object has an attribute in Python

前端 未结 14 2089
无人及你
无人及你 2020-11-22 12:19

Is there a way in Python to determine if an object has some attribute? For example:

>>> a = SomeClass()
>>> a.someProperty = value
>>         


        
14条回答
  •  囚心锁ツ
    2020-11-22 13:11

    This is super simple, just use dir(object)
    This will return a list of every available function and attribute of the object.

提交回复
热议问题