(object)
Work out which source or compiled file an object was defined in.
Work out which source or compiled file an object was defined in.
Work out which source or compiled file an object was defined in .
def getfile(object):
    """Work out which source or compiled file an object was defined in."""
    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.__func__
    if isfunction(object):
        object = object.__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 . __func__ if isfunction ( object ) : object = object . __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 ) )