def extract_inner_value(source, attr_chain):
 cur_element = source
 for attr in attr_chain:
  if hasattr(cur_element, '__getitem__'):
   try:
    cur_element = cur_element[attr]
    continue
   except (KeyError, TypeError):
    pass
  cur_element = getattr(cur_element, attr, None)
  if (cur_element is None):
   return None
 return cur_element

def extract_inner_value ( source , attr_chain ) : cur_element = source for attr in attr_chain : if hasattr ( cur_element , '__getitem__' ) : try : cur_element = cur_element [ attr ] continue except ( KeyError , TypeError ) : pass cur_element = getattr ( cur_element , attr , None ) if ( cur_element is None ) : return None return cur_element
search for a stored value by recursing through dict keys and attributes .