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

builtins.exec

Prev: builtins.eval | Up: builtins | Next: builtins.exit
Rel: builtins.abs, builtins.aiter, builtins.all, builtins.anext
Ref: docs.python.org — builtins.exec
Tags: #public #python3 #stdlib #builtins


Import

import builtins
from builtins import exec

Signature & Overview

builtins.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("total = sum([1, 2, 3])", ns)
assert ns["total"] == 6

Gotchas

REPL Inspect

from builtins import exec
help(exec)

Linked from

Related notes