python check if has attribute

57

python check if has attribute -

if hasattr(a, 'property'):
    a.property

check if an object has an attribute in Python -

if hasattr(a, 'property'):
    doStuff(a.property)
else:
    otherStuff()

Comments

Submit
0 Comments