Runtime Data Attributes

frame.f_locals

Frame local namespace. Python 3.13 optimized scopes expose a write-through proxy, unlike ordinary locals() snapshots; unoptimized scopes may expose a dictionary. Avoid retaining frames or dumping private values.

Formal Syntax & Structure

python syntaxpython
frame.f_locals

Return Value

mapping

Value exposed by this attribute; availability and mutability depend on the owner as described.

Working Example

Example Snippetpython
import inspectdef f():    x = 2    frame = inspect.currentframe()    try:        frame.f_locals['x'] = 9        return x    finally:        del frameprint(f())
Python Reference