退出 ipython
我非常喜欢 IPython,因为它可以与 python 解释器一起使用。但是,我不断发现自己输入 exit
退出,并收到提示“输入 exit() 退出”。
我知道我可以输入 Ctrl-D 退出,但是有没有办法可以输入不带括号的 exit
并让 IPython 退出?
更新:感谢nosklo,通过将以下行添加到主文件中可以轻松完成此操作ipy_user_conf.py
中的 () 函数:
# type exit to exit
ip.ex("type(exit).__repr__ = lambda s: setattr(s.shell, 'exit_now', True) or ''")
I like IPython a lot for working with the python interpreter. However, I continually find myself typing exit
to exit, and get prompted "Type exit() to exit."
I know I can type Ctrl-D to exit, but is there a way I can type exit
without parentheses and get IPython to exit?
Update: Thanks to nosklo, this can be easily done by adding the following line to the main() function in your ipy_user_conf.py
:
# type exit to exit
ip.ex("type(exit).__repr__ = lambda s: setattr(s.shell, 'exit_now', True) or ''")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你可以像这样使用它:
编辑:
我自己不使用
ipython
,但它似乎有一些奇怪的sys.exit
处理程序。我找到的解决方案如下:
使用方法:
You can use it like this:
EDIT:
I dont use
ipython
myself, but it seems to have some wierdsys.exit
handler.The solution I found is as follows:
Usage:
%exit
或%Exit
(如果您启用了确认并想跳过它)。您可以通过将
execute __IPYTHON__.magic_e = __IPYTHON__.magic_exit
放入 ipythonrc 中,将其别名为%e
。%exit
, or%Exit
, if you have confirmation enabled and want to skip it.You can alias it to e.g.
%e
by puttingexecute __IPYTHON__.magic_e = __IPYTHON__.magic_exit
in your ipythonrc.使用 iPython 6.2.1,您只需输入
exit
即可退出解释器:With iPython 6.2.1, you can simply type
exit
to exit the interpreter:至少在 IPython 0.10 中,您应该能够设置 IPYTHON.rc.confirm_exit = False
At least in IPython 0.10, you should be able to set IPYTHON.rc.confirm_exit = False
在 Linux 上,我发现自己经常使用 ctrl-d 退出每种类型的 REPL 接口,包括 ipython。几乎总是需要输入退出/注销。
On Linux, I find myself constantly using ctrl-d to exit from every type REPL interface, including ipython. There is need to type exit/logout almost always.