def safe_getattr(obj, name, *defargs):
 try:
  return getattr(obj, name, *defargs)
 except Exception:
  if defargs:
   return defargs[0]
  raise AttributeError(name)

def safe_getattr ( obj , name , * defargs ) : try : return getattr ( obj , name , * defargs ) except Exception : if defargs : return defargs [ 0 ] raise AttributeError ( name )
a getattr() that turns all exceptions into attributeerrors .