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

exec

Prev: eval | Up: __builtins__ | Next: exit
Rel: breakpoint, compile, eval, globals, input
Ref: docs.python.org — exec
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import exec

Overview & Signature

exec(source, /, globals=None, locals=None, *, closure=None)

Execute the given source in the context of globals and locals.

Usage

ns: dict[str, object] = {}
exec("x = 6 * 7", ns)
assert ns["x"] == 42

Gotchas

REPL Inspect

help(exec)

Linked from

Related notes