IPython,每次关闭终端前提示

IPython, prompt each time before closing the terminal

我在 Ubuntu 14.04 上使用 IPython 1.2.1。我已经检查了所有设置和配置文件首选项,但我找不到每次关闭 window.

时都会提示的命令

如何让 IPython 每次关闭终端前提示我?

有时,我不小心关闭了终端,终端打开的所有图表都丢失了。

根据 documentation 应该这样做:

-[no]confirm_exit
    Set to confirm when you try to exit IPython with an EOF 
    (Control-D in Unix, Control-Z/Enter in Windows). Note 
    that using the magic functions @Exit or @Quit you can 
    force a direct exit, bypassing any confirmation.

例如,要在退出前启用确认:

$ ipython -confirm_exit

那个版本好像有点老了。我是 Cygwin 上的 运行 v2.3.0。

您可以在配置文件中设置。此文件的位置取决于您的平台、版本、您的用户配置文件以及您的安装方式 IPython.

例如,在我的一个盒子上(Linux,几乎是默认安装,v3.1.0),它位于 $HOME/.ipython/profile_default/ipython_config.py

这个文件看起来像

c = get_config()
... ...
c.TerminalInteractiveShell.confirm_exit = False

用于我的安装和用户配置文件。您可以将此标志设置为 True.


编辑:仅当您通过向交互式解释器提供 EOF 字符 (Ctrl + d 退出时才有效。如果您通过键入 quitexit 退出,它没有任何效果。如果你杀死了包含实时会话的终端仿真器,那么,你得到了你应得的 ;)