def getattr_recursive(item, attr_key, *args):
 using_default = (len(args) >= 1)
 default = (args[0] if using_default else None)
 for attr_key in attr_key.split('.'):
  try:
   if isinstance(item, dict):
    item = item.__getitem__(attr_key)
   else:
    item = getattr(item, attr_key)
  except (KeyError, AttributeError):
   if using_default:
    return default
   raise
 return item

def getattr_recursive ( item , attr_key , * args ) : using_default = ( len ( args ) >= 1 ) default = ( args [ 0 ] if using_default else None ) for attr_key in attr_key . split ( '.' ) : try : if isinstance ( item , dict ) : item = item . __getitem__ ( attr_key ) else : item = getattr ( item , attr_key ) except ( KeyError , AttributeError ) : if using_default : return default raise return item
get attributes recursively .