def text_repr(value):
 try:
  return pydoc.text.repr(value)
 except KeyboardInterrupt:
  raise
 except:
  try:
   return repr(value)
  except KeyboardInterrupt:
   raise
  except:
   try:
    name = getattr(value, '__name__', None)
    if name:
     return text_repr(name)
    klass = getattr(value, '__class__', None)
    if klass:
     return ('%s instance' % text_repr(klass))
   except KeyboardInterrupt:
    raise
   except:
    return 'UNRECOVERABLE REPR FAILURE'

def text_repr ( value ) : try : return pydoc . text . repr ( value ) except KeyboardInterrupt : raise except : try : return repr ( value ) except KeyboardInterrupt : raise except : try : name = getattr ( value , '__name__' , None ) if name : return text_repr ( name ) klass = getattr ( value , '__class__' , None ) if klass : return ( '%s instance' % text_repr ( klass ) ) except KeyboardInterrupt : raise except : return 'UNRECOVERABLE REPR FAILURE'
hopefully pretty robust repr equivalent .