In Objective-C you can do [variable valueForKeyPath:@"abc.def"] or [[variable abc] def] and if abc doesn’t exist on variable you’ll get a nil value in the end and will not get an error or exception. This is really convenient. Is there something like this in Python? I know you can do (for dictionaries at least)
abc = variable.get('abc', None)
if abc:
def = abc.get('def', None)
or
try:
def = variable.get('abc').get('def')
except:
pass
which seems incredibly verbose. Is there an easier way when I just want to access an object’s attribute or get a None value back?
what about
well, this will only work for dict..