code
— 解释器基类
¶
源代码: Lib/code.py
The
code
module provides facilities to implement read-eval-print loops in Python. Two classes and convenience functions are included which can be used to build applications which provide an interactive interpreter prompt.
- class 代码。 InteractiveInterpreter ( locals = None ) ¶
-
This class deals with parsing and interpreter state (the user’s namespace); it does not deal with input buffering or prompting or input file naming (the filename is always passed in explicitly). The optional locals argument specifies a mapping to use as the namespace in which code will be executed; it defaults to a newly created dictionary with key
'__name__'设为'__console__'and key'__doc__'设为None.
- class 代码。 InteractiveConsole ( locals = None , filename = '<console>' , local_exit = False ) ¶
-
密切模拟交互式 Python 解释器的行为。此类构建于
InteractiveInterpreter和添加提示使用熟悉的sys.ps1andsys.ps2, and input buffering. If local_exit 为 True,exit()andquit()in the console will not raiseSystemExit, but instead return to the calling code.Changed in version 3.13: 添加 local_exit 参数。