兩種方法:
1. 在每個新建文件開始處添加如下兩行(僅對當前文件有效):
from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all"
2. 直接添加配置文件(對所有文件生效):
vi ~/.ipython/profile_default/ipython_config.py
配置文件內容如下:
c = get_config() #Run all nodes interactively c.InteractiveShell.ast_node_interactivity = "all"
效果如下: