inspect.getsourcelines()
inspect.getsourcelines() is a Python function in the Inspect Module category. Returns (lines, lineno) tuple where lines is a list of source code lines. The syntax is inspect.getsourcelines(object). Returns: (list_of_lines, starting_line) tuple. A typical example: lines, start = inspect.getsourcelines(os.getcwd)
print(f"Starts at line {start}"). 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.getfile(), which returns the file path where an object is defined. 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). More about this category: Object introspection — getsource, getfile, getmembers, signature. Related Inspect Module entries: inspect.getsource(), inspect.getfile(), inspect.getmembers(), inspect.signature(), inspect.isfunction(), inspect.ismethod(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.