MCPcopy Index your code
hub / github.com/python/cpython / interactive_console

Function interactive_console

Lib/_pyrepl/main.py:25–58  ·  view source on GitHub ↗
(mainmodule=None, quiet=False, pythonstartup=False)

Source from the content-addressed store, hash-verified

23
24
25def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
26 if not CAN_USE_PYREPL:
27 if not os.getenv('PYTHON_BASIC_REPL') and FAIL_REASON:
28 from .trace import trace
29 trace(FAIL_REASON)
30 print(FAIL_REASON, file=sys.stderr)
31 return sys._baserepl()
32
33 if not mainmodule:
34 mainmodule = types.ModuleType("__main__")
35
36 namespace = mainmodule.__dict__
37
38 # sys._baserepl() above does this internally, we do it here
39 startup_path = os.getenv("PYTHONSTARTUP")
40 if pythonstartup and startup_path:
41 sys.audit("cpython.run_startup", startup_path)
42
43 import tokenize
44 with tokenize.open(startup_path) as f:
45 startup_code = compile(f.read(), startup_path, "exec")
46 exec(startup_code, namespace)
47
48 # set sys.{ps1,ps2} just before invoking the interactive interpreter. This
49 # mimics what CPython does in pythonrun.c
50 if not hasattr(sys, "ps1"):
51 sys.ps1 = ">>> "
52 if not hasattr(sys, "ps2"):
53 sys.ps2 = "... "
54
55 from .console import InteractiveColoredConsole
56 from .simple_interact import run_multiline_interactive_console
57 console = InteractiveColoredConsole(namespace, filename="<stdin>")
58 run_multiline_interactive_console(console)

Callers

nothing calls this directly

Calls 6

traceFunction · 0.90
compileFunction · 0.50
openMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…