Asked • 04/07/19

How to know if an object has an attribute in Python?

Is there a way in Python to determine if an object has some attribute? For example: >>> a = SomeClass() >>> a.someProperty = value >>> a.property Traceback (most recent call last): File "", line 1, in AttributeError: SomeClass instance has no attribute 'property'How can you tell if a has the attribute property before using it?

1 Expert Answer

By:

Reet C. answered • 04/09/19

Tutor
5 (10)

Computer Engineer With A Passion For Teaching!

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.