禁用IPython退出确认

129

每次我输入exit()都会弹出确认退出的提示,真的很烦人。当然我想退出啊!否则我也不会写exit()了!

有没有办法覆盖IPython的默认行为,使其在退出时不提示?


3
如果你想升级到IPython 0.11版本,使用exit命令不会再询问是否确认退出。(但是若你意外按下Ctrl-d仍然会提示确认退出) - Thomas K
4个回答

146
如果你想使Ctrl-D键退出IPython时无需确认,请在IPython 0.11中添加c.TerminalInteractiveShell.confirm_exit = False到你的配置文件*中。
如果你还没有配置文件,请运行ipython profile create创建一个。
如果你使用Django shell,请注意这个ticket
* 配置文件位于:$HOME/.ipython/profile_default/ipython_config.py

对于已经设置了此环境变量的人来说,配置文件位于$IPYTHONDIR/profile_default/ipython_config.py - smac89

47
在ipython版本0.11或更高版本中,
  1. Run with --no-confirm-exit OR
  2. Exit via 'exit' instead of control-D OR
  3. Make sure the directory exists (or run ipython profile create to create it) and add these lines to $HOME/.ipython/profile_default/ipython_config.py:

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

在Linux中,首选使用~/.config/ipython/profile_default/ipython_config.py以匹配freedesktop.org。适用于1.2.1版本。 - Ciro Santilli OurBigBook.com
“alias ipython="ipython --no-confirm-exit --no-banner"` 已成为我启动 IPython 的首选方式。 - jwalton

19

只需键入带有大写字母 EExit即可。

或者使用以下命令启动IPython:

$ ipython -noconfirm_exit

或者对于较新版本的IPython:

$ ipython --no-confirm-exit 

22
@Brendan,关于使其永久化,您还可以在您的ipythonrc配置文件中设置:confirm_exit 0 - nye17
2
很好,使用别名设置它,工作完成。不要瞎搞创建配置文件或更改配置。 - Tom Busby

5

我喜欢这个配置建议,但在我学习之前,我已经开始使用“退出”键组合。

Ctrl+\

或者

Ctrl+4

这样做会终止当前运行的程序,没有时间进行确认。

11
这不是一个好的做法,这会导致内核向IPython发送SIGQUIT信号,没有给IPython进程清理自己的机会。 - georgexsh
它通过更改“stty”的输出破坏了我的机器上的“sudo”。 - darw

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接