I need something like this (pseudocode):
if hasattr(object, 'detail.infotext')
I mean I want to check if object has attribute details
and if it has, then if details
has a attribute named infotext
I could do it like this:
if hasattr(object, 'detail'):
if hasattr(object.detail, 'infotext'):
do something
But one-liners are so much easier to read.
I know this isn't really what you want to do, but it's more pythonic anyway (if you know the names of the attributes you're looking for explicitly):
try:
do something with object.detail.infotext
except AttributeError:
do something else
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With