inspect.getfile()
inspect.getfile() is a Python function in the Inspect Module category. Returns the file path where an object is defined. The syntax is inspect.getfile(object). Returns: File path string. A typical example: inspect.getfile(os) # "/usr/lib/python3.12/os.py"
inspect.getfile(print) # "/usr/lib/python3.12/builtins.py". A close sibling is inspect.getsource(), which returns the source code of a module, class, method, function, or code object. A close sibling is inspect.getmembers(), which returns all members of an object as (name, value) pairs, optionally filtered. A close sibling is inspect.signature(), which returns the Signature object for a callable (parameters, return annotation). A close sibling is inspect.isfunction(), which returns True if the object is a regular Python function. More about this category: Object introspection — getsource, getfile, getmembers, signature. Related Inspect Module entries: inspect.getsource(), inspect.getmembers(), inspect.signature(), inspect.isfunction(), inspect.ismethod(), inspect.isclass(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.