inspect.getgeneratorlocals
Prev: inspect.getfullargspec | Up: inspect | Next: inspect.getgeneratorstate
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.getgeneratorlocals
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import getgeneratorlocals
Signature & Overview
inspect.getgeneratorlocals(generator)
Get the mapping of generator local variables to their current values.
Usage
import inspect
def gen():
step = 1
yield step
step = 2
yield step
g = gen()
next(g)
assert inspect.getgeneratorlocals(g) == {"step": 1}
Gotchas
- Returns
{}after the generator finishes (GEN_CLOSED).
REPL Inspect
from inspect import getgeneratorlocals
help(getgeneratorlocals)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/getfullargspec Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/getgeneratorstate 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