天天看点

Jupyter cell同时输出多行

如果对带有一个变量或是未赋值语句的cell执行操作,Jupyter将会自动打印该变量而无需一个输出语句。

第一种方法:

在代码最上方cell添加

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

第二种方法: 设置所有的Jupyter实例

1. mac 终端输入如下命令,创建ipython_config.py文件

vim ~/.ipython/profile_default/ipython_config.py
           

2. 在文件中输入如下内容:

c = get_config()
c.InteractiveShell.ast_node_interactivity = "all"
           

3. 按ESC后,输入”wq“,保存并退出文件。

cat 查看ipython_config.py中的内容,确保正确   

Jupyter cell同时输出多行

4. 输入如下命令,使上述代码生效

source ~/.ipython/profile_default/ipython_config.py
           

效果 如下

Jupyter cell同时输出多行