要在我使用的单元格中显示多个输出,
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
但是,如果我有一个单元格,我只想要一个输出,我该如何切换回同一个笔记本。
我尝试发行
InteractiveShell.ast_node_interactivity = "last_expr"
在我想要单个输出的单元格中,但它似乎不起作用。
最佳答案
您可以在 IPython(终端、笔记本等)提示符中发出以下命令:
%config
它会告诉您可以配置哪个对象:
Available objects for config:
AliasManager
DisplayFormatter
HistoryManager
IPCompleter
IPKernelApp
InlineBackend
LoggingMagics
MagicsManager
PrefilterManager
ScriptMagics
StoreMagics
ZMQInteractiveShell
请注意,ZMQInteractiveShell
将是终端中的 TerminalInteractiveShell
。在我们的例子中,即我们感兴趣的配置,让我们向 config
询问更多信息:
%config ZMQInteractiveShell
ZMQInteractiveShell options
-------------------------
ZMQInteractiveShell.ast_node_interactivity=<Enum>
Current: 'last_expr'
Choices: ['all', 'last', 'last_expr', 'none', 'last_expr_or_assign']
'all', 'last', 'last_expr' or 'none', 'last_expr_or_assign' specifying which
nodes should be run interactively (displaying output from expressions).
ZMQInteractiveShell.ast_transformers=<List>
Current: []
哦!那么我们来分配一下:
%config InteractiveShell.ast_node_interactivity="last_expr"
您已经准备好开始了,而且您还学习了如何深入了解 IPython 配置系统。
请注意,它可能不适用于所有配置选项(如果是这样,请打开错误报告),但它应该适用于 last_node_interactivity
,并且解析器有点挑剔,您可能不需要周围有空格=
。
享受吧!
关于python - 是否可以在 Jupyter Notebook 单元中在显示多个输出和单个输出之间来回切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47436322/