On this page
code.InteractiveInterpreter
Prev: code.InteractiveConsole | Up: code
Rel: code.compile_command, code.interact, code.InteractiveConsole
Ref: docs.python.org — code.InteractiveInterpreter
Tags: #public #python3 #stdlib #code
Import
import code
from code import InteractiveInterpreter
Signature & Overview
code.InteractiveInterpreter(locals=None)
Base class for InteractiveConsole.
Methods & Attributes
InteractiveInterpreter.runcode(self, code)— Execute a code object.InteractiveInterpreter.runsource(self, source, filename='<input>', symbol='single')— Compile and run some source in the interpreter.InteractiveInterpreter.showsyntaxerror(self, filename=None, **kwargs)— Display the syntax error that just occurred.InteractiveInterpreter.showtraceback(self)— Display the exception that just occurred.InteractiveInterpreter.write(self, data)— Write a string.
Usage
import code
ns: dict[str, object] = {}
interp = code.InteractiveInterpreter(locals=ns)
assert interp.runsource("total = 21 + 21") is False
assert ns["total"] == 42
Gotchas
runsource()returnsTruefor incomplete multi-line input,Falseonce executed (or after printing a syntax/runtime error to stderr).
REPL Inspect
from code import InteractiveInterpreter
help(InteractiveInterpreter)
Linked from
Related notes
- tuts/python3/stdlib_module/code/compile_command Linked here; links to this page; shared tags: #code, #stdlib
- tuts/python3/stdlib_module/code/interact Linked here; links to this page; shared tags: #code, #stdlib
- tuts/python3/stdlib_module/code/InteractiveConsole Linked here; links to this page; shared tags: #code, #stdlib
- tuts/python3/stdlib_module/code Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib