简体   繁体   中英

IPython, prompt each time before closing the terminal

I am using IPython 1.2.1 on Ubuntu 14.04. I have checked all the settings and profile preferences, but I cannot find a command which would prompt each time I close the window.

How I can make IPython prompt me each time before I close the terminal?

Sometimes, by mistake, I close the terminal and every graph that was opened by the terminal get lost.

According to the documentation this should do it:

-[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.

For example, to enable confirmation before exiting:

$ ipython -confirm_exit

That version seems a little old. I'm running v2.3.0 on Cygwin.

You can set it in the config file. The location of this file depends on your platform, version, your user profile and how you installed IPython.

For example, on one of my boxes (Linux, pretty much default installation, v3.1.0), it is located at $HOME/.ipython/profile_default/ipython_config.py

This file looks like

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

for my installation and user profile. You can set this flag to True .


Edit: This is only effective if you exit by feeding the interactive interpreter the EOF character ( Ctrl + d ). If you quit by typing quit or exit , it has no effect. If you kill your terminal emulator containing a live session, well, you get what you deserve ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM