On this page
locals
Prev: list | Up: __builtins__ | Next: map
Rel: breakpoint, compile, eval, exec, globals
Ref: docs.python.org — locals
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import locals
Overview & Signature
locals()
Return a dictionary containing the current scope's local variables.
Usage
def compute():
a, b = 3, 4
return locals()
assert compute() == {"a": 3, "b": 4}
Gotchas
- Do NOT mutate
locals()inside a function: Changes to the returned dict inside function scopes do not reliably update local variables.
REPL Inspect
help(locals)
Linked from
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/list Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/map Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/breakpoint Linked here; shared tags: #builtins
- tuts/python3/__builtins__/compile Linked here; shared tags: #builtins
- tuts/python3/__builtins__/eval Linked here; shared tags: #builtins
- tuts/python3/__builtins__/exec Linked here; shared tags: #builtins
- tuts/python3/__builtins__/globals Linked here; shared tags: #builtins
- tuts/c/builtins shared tags: #builtins