天天看點

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同時輸出多行