Periksa apakah suatu objek memiliki atribut di Python
if hasattr(a, 'property'):
doStuff(a.property)
else:
otherStuff()
DreamCoder
if hasattr(a, 'property'):
doStuff(a.property)
else:
otherStuff()
getattr(a, 'property', 'default value')
assert hasattr(a, 'property'), 'object lacks property'
print(a.property)