On this page
  1. inspect.getblock
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from inspect import getblock
help(getblock)

Linked from

Related notes