On this page
inspect.getblock
Prev: inspect.getattr_static | Up: inspect | Next: inspect.getcallargs
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.getblock
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import getblock
Signature & Overview
inspect.getblock(lines)
Extract the block of code at the top of the given list of lines.
Usage
import inspect
lines = ["def f():\n", " return 1\n", "x = 2\n"]
assert inspect.getblock(lines) == ["def f():\n", " return 1\n"]
Gotchas
- Extracts the first indented Python block from a list of source lines: Usually called indirectly via
inspect.getsourcelines().
REPL Inspect
from inspect import getblock
help(getblock)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/getattr_static Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/getcallargs 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