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 ''")
Once you've clicked anywhere in the IPython Console Window (again, the output window), then, once you press ctrl+c, your program will terminate. If the IPython Console doesn't have focus when you press ctrl+c, it won't know you mean to terminate the program, and so it will ignore the ctrl+c.
After all of your notebooks are closed and shut down, you can end your Jupyter Notebook session by clicking on the QUIT button at the top right of the dashboard. You can now close the browswer tab for Jupyter Notebook . If desired, you can also close your terminal by typing the command exit and hitting Enter .
The easiest way is to run easy_install ipython[all] as an administrator (start button, type cmd , shift+right click on “cmd.exe” and select “Run as administrator”). This installs the latest stable version of IPython including the main required and optional dependencies.
IPython bridges this gap, and gives you a syntax for executing shell commands directly from within the IPython terminal. The magic happens with the exclamation point: anything appearing after ! on a line will be executed not by the Python kernel, but by the system command-line.
>>> 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
%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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With