On this page
inspect.findsource
Prev: inspect.EndOfBlock | Up: inspect | Next: inspect.formatannotation
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.findsource
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import findsource
Signature & Overview
inspect.findsource(object)
Return the entire source file and starting line number for an object.
Usage
import inspect
import json
lines, start_lineno = inspect.findsource(json.dumps)
assert isinstance(lines, list) and start_lineno >= 0
Gotchas
- Fails on C built-ins and dynamically
exec()ed code: RaisesOSError/TypeErrorwhen source files aren't on disk.
REPL Inspect
from inspect import findsource
help(findsource)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/EndOfBlock Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/formatannotation Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib