Python 如何在 Jupyter 中显示完整输出,而不仅仅是最后结果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36786722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:21:02  来源:igfitidea点击:

How to display full output in Jupyter, not only last result?

pythonipythonjupyter

提问by mbh86

I want Jupyter to print all the interactive output without resorting to print, not only the last result. How to do it?

我希望 Jupyter 打印所有交互式输出而不诉诸打印,而不仅仅是最后的结果。怎么做?

Example :

例子 :

a=3
a
a+1

I would like to display

我想显示

3
4

3
4

回答by mbh86

Thanks to Thomas, here is the solution I was looking for:

感谢 Thomas,这是我一直在寻找的解决方案:

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

回答by William

https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/

https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/

1) Place this code in a Jupyter cell:

1) 将此代码放在 Jupyter 单元格中:

from IPython.core.interactiveshell import InteractiveShell

InteractiveShell.ast_node_interactivity = "all"

2) In Windows, the steps below makes the change permanent. Should work for other operating systems. You might have to change the path.

2) 在 Windows 中,以下步骤使更改永久化。应该适用于其他操作系统。您可能需要更改路径。

C:\Users\your_profile\.ipython\profile_default

Make a ipython_config.py file in the profile_defaults with the following code:

使用以下代码在 profile_defaults 中创建一个 ipython_config.py 文件:

c = get_config()

c.InteractiveShell.ast_node_interactivity = "all"