(object)
Return the filename that can be used to locate an object's source.
    Return None if no way can be identified to get the source.
Return the filename that can be used to locate an object's source.
    Return None if no way can be identified to get the source.
Return the filename that can be used to locate an object s source . Return None if no way can be identified to get the source .
def getsourcefile(object):
    """Return the filename that can be used to locate an object's source.
    Return None if no way can be identified to get the source.
    """
    filename = getfile(object)
    if filename[-4:].lower() in ('.pyc', '.pyo'):
        filename = filename[:-4] + '.py'
    for suffix, mode, kind in imp.get_suffixes():
        if 'b' in mode and filename[-len(suffix):].lower() == suffix:
            # Looks like a binary file.  We want to only return a text file.
            return None
    if os.path.exists(filename):
        return filename
    # only return a non-existent filename if the module has a PEP 302 loader
    if hasattr(getmodule(object, filename), '__loader__'):
        return filename
    # or it is in the linecache
    if filename in linecache.cache:
        return filename
def getsourcefile ( object ) : filename = getfile ( object ) if filename [ - 4 : ] . lower ( ) in ( '.pyc' , '.pyo' ) : filename = filename [ : - 4 ] + '.py' for suffix , mode , kind in imp . get_suffixes ( ) : if 'b' in mode and filename [ - len ( suffix ) : ] . lower ( ) == suffix : # Looks like a binary file.  We want to only return a text file. return None if os . path . exists ( filename ) : return filename # only return a non-existent filename if the module has a PEP 302 loader if hasattr ( getmodule ( object , filename ) , '__loader__' ) : return filename # or it is in the linecache if filename in linecache . cache : return filename