Answers for "check if an object has an attribute in Python"

0

check if an object has an attribute in Python

getattr(a, 'property', 'default value')
Posted by: Guest on April-26-2022
0

check if an object has an attribute in Python

if hasattr(a, 'property'):
    doStuff(a.property)
else:
    otherStuff()
Posted by: Guest on April-26-2022
0

check if an object has an attribute in Python

assert hasattr(a, 'property'), 'object lacks property' 
print(a.property)
Posted by: Guest on April-26-2022

Code answers related to "check if an object has an attribute in Python"

Python Answers by Framework

Browse Popular Code Answers by Language