def safe_getmembers(object, predicate=None):
 results = []
 for key in dir(object):
  try:
   value = safe_getattr(object, key, None)
  except AttributeError:
   continue
  if ((not predicate) or predicate(value)):
   results.append((key, value))
 results.sort()
 return results

def safe_getmembers ( object , predicate = None ) : results = [ ] for key in dir ( object ) : try : value = safe_getattr ( object , key , None ) except AttributeError : continue if ( ( not predicate ) or predicate ( value ) ) : results . append ( ( key , value ) ) results . sort ( ) return results
a version of inspect .