def getfile(object):
 if ismodule(object):
  if hasattr(object, '__file__'):
   return object.__file__
  raise TypeError('{!r} is a built-in module'.format(object))
 if isclass(object):
  object = sys.modules.get(object.__module__)
  if hasattr(object, '__file__'):
   return object.__file__
  raise TypeError('{!r} is a built-in class'.format(object))
 if ismethod(object):
  object = object.im_func
 if isfunction(object):
  object = object.func_code
 if istraceback(object):
  object = object.tb_frame
 if isframe(object):
  object = object.f_code
 if iscode(object):
  return object.co_filename
 raise TypeError('{!r} is not a module, class, method, function, traceback, frame, or code object'.format(object))

def getfile ( object ) : if ismodule ( object ) : if hasattr ( object , '__file__' ) : return object . __file__ raise TypeError ( '{!r} is a built-in module' . format ( object ) ) if isclass ( object ) : object = sys . modules . get ( object . __module__ ) if hasattr ( object , '__file__' ) : return object . __file__ raise TypeError ( '{!r} is a built-in class' . format ( object ) ) if ismethod ( object ) : object = object . im_func if isfunction ( object ) : object = object . func_code if istraceback ( object ) : object = object . tb_frame if isframe ( object ) : object = object . f_code if iscode ( object ) : return object . co_filename raise TypeError ( '{!r} is not a module, class, method, function, traceback, frame, or code object' . format ( object ) )
work out which source or compiled file an object was defined in .