How to check if a Object has an Attribute in Python

To check if a Object has an Attribute in Python you can use the snippet below.

Sample Python

if hasattr(myObject, 'myAttributeName'): # myObject.myAttributeName exists.

Please Share us:
Please rate this snippet

6 thoughts on “How to check if a Object has an Attribute in Python

Leave a Reply