def n_deep(obj, names):
 for name in names:
  try:
   obj = getattr(obj, name)
  except KeyError:
   raise APIError(('This object is missing the %s attribute.' % name), obj)
 return obj

def n_deep ( obj , names ) : for name in names : try : obj = getattr ( obj , name ) except KeyError : raise APIError ( ( 'This object is missing the %s attribute.' % name ) , obj ) return obj
a function to descend len levels in an object and retrieve the attribute there .