Answers for "how to check if an attribute exists in python"

11

python check if has attribute

if hasattr(a, 'property'):
    a.property
Posted by: Guest on May-19-2020
1

python check if attribute exists in class

if hasattr(obj, 'propertyName'):
	...
Posted by: Guest on March-10-2021
3

python3 check if object has attribute

try:
    doStuff(a.property)
except AttributeError:
    otherStuff()
Posted by: Guest on February-08-2020

Code answers related to "how to check if an attribute exists in python"

Python Answers by Framework

Browse Popular Code Answers by Language