ipython TerminalInteractiveShell和InteractiveShell之间有什么区别?

2024-06-26 13:03:26 发布

您现在位置:Python中文网/ 问答频道 /正文

ipython documentation有一长串可配置选项。一些用于TerminalInteractiveShell,一些用于InteractiveShell。当我从命令行生成一个ipython_config.py时,一些选项出现在文档中的一个选项和另一个选项中。这有什么道理吗?两者兼有的原因是什么


Tags: 命令行文档pyconfigdocumentation选项ipython原因
1条回答
网友
1楼 · 发布于 2024-06-26 13:03:26

通过查看文档中的list of modules,我们发现

IPython.core.application: An application for IPython.

IPython.core.interactiveshell: Main IPython class.

IPython.terminal.ipapp: The Application object for the command line ipython program.

IPython.terminal.interactiveshell: IPython terminal interface using prompt_toolkit

^{}是基本的iPython外壳类,可以为不同的目的对其进行子类化^{}就是这样一个特殊的子类。它继承自InteractiveShell,是在命令行中键入“ipython”时运行的特定shell

一个可用于TerminalInteractiveShell不是的配置选项的示例是InteractiveShell^{}。这似乎是合理的,因为“你真的想退出吗”这个问题只有在外壳内有人按下Control-D时才真正相关

实际上,如果您只是试图配置命令行ipythonshell,那么更改选项的InteractiveShellTerminalInteractiveShell版本都会起作用,因为TerminalInteractiveShell继承了基类的选项。但是,只编辑更具体的TerminalInteractiveShell类更安全,因为基类仍然在非终端情况下使用,更改其设置可能会导致意外行为。例如:

希望这是有帮助的

相关问题 更多 >