exit from ipython

%exit, or %Exit, if you have confirmation enabled and want to skip it. You can alias it to e.g. %e by putting execute __IPYTHON__.magic_e = __IPYTHON__.magic_exit in your ipythonrc.


With iPython 6.2.1, you can simply type exit to exit the interpreter:

$ ipython
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: exit
$ 

>>> import sys
>>> class Quitter(object):
...     def __repr__(self):
...         sys.exit()
... 
>>> exit = Quitter()

You can use it like this:

>>> exit

EDIT:

I dont use ipython myself, but it seems to have some wierd sys.exit handler. The solution I found is as follows:

In [1]: type(exit).__repr__ = lambda s: setattr(s.shell, 'exit_now', True) or ''

Usage:

In [2]: exit