【发布时间】:2021-01-15 21:28:30
【问题描述】:
ipython documentation 有一长串可配置选项。有些是针对TerminalInteractiveShell,有些是针对InteractiveShell。当我从命令行生成ipython_config.py 时,一些选项出现在文档中的一个和另一个中。这有什么押韵或理由吗?两者兼有的原因是什么?
【问题讨论】:
标签: python configuration ipython
ipython documentation 有一长串可配置选项。有些是针对TerminalInteractiveShell,有些是针对InteractiveShell。当我从命令行生成ipython_config.py 时,一些选项出现在文档中的一个和另一个中。这有什么押韵或理由吗?两者兼有的原因是什么?
【问题讨论】:
标签: python configuration ipython
查看文档中的list of modules,我们有
IPython.core.application:IPython 的应用程序。
IPython.core.interactiveshell:IPython 主类。
IPython.terminal.ipapp: 命令行的 Application 对象ipython程序。
IPython.terminal.interactiveshell: IPython 终端接口使用 prompt_toolkit
InteractiveShell 是基本的 iPython shell 类,可以为不同的目的进行子类化。 TerminalInteractiveShell 就是这样一个特定的子类。它继承自InteractiveShell,是我们在命令行中键入“ipython”时运行的特定shell。
一个可用于TerminalInteractiveShell 但不是基本InteractiveShell 的配置选项示例是confirm_exit。这似乎是合理的,因为“你真的要退出吗”这个问题只有在外壳内有人按下 Control-D 时才真正相关。
实际上,如果您只是尝试配置命令行 ipython shell,则更改选项的InteractiveShell 或TerminalInteractiveShell 版本将起作用,因为TerminalInteractiveShell 继承了基类的选项。但是,只编辑更具体的TerminalInteractiveShell 更安全,因为基类仍在非终端情况下使用,并且更改其设置可能会导致出现意外行为。例如:
This Jupyter Notebook tutorial 使用 InteractiveShell 将笔记本代码单元转换为可执行 Python
ipython 源代码中的This test class 为每个测试创建一个shell(继承自普通InteractiveShell)。
希望这对您有所帮助!
【讨论】: