PyDocs

Nav

Python Runtime Services

exec

builtins

function
  • exec(source, /, globals=None, locals=None, *, closure=None)
Execute the given source in the context of globals and locals.

The source may be a string representing one or more Python statements
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
The closure must be a tuple of cellvars, and can only be used
when source is a code object requiring exactly that many cellvars.
Changed in 3.11, 3.13, 3.15
  • 3.11: Added the closure parameter.
  • 3.13: The globals and locals arguments can now be passed as keywords.
  • 3.13: The semantics of the default locals namespace have been adjusted as described for the locals() builtin.
  • 3.15: globals can now be a frozendict.
0 Examples
No examples for builtins/exec.
See Also
No see-alsos for builtins/exec
0 Notes
No notes for exec