exit
IPython 中的函数与exit
Python 中的函数不同。在 IPython 中,exit
是一个实例IPython.core.autocall.ExitAutocall
:
In [6]: exit?
Type: ExitAutocall
String Form:<IPython.core.autocall.ExitAutocall object at 0x9f4c02c>
File: /data1/unutbu/.virtualenvs/arthur/local/lib/python2.7/site-packages/ipython-0.14.dev-py2.7.egg/IPython/core/autocall.py
Definition: exit(self)
Docstring:
An autocallable object which will be added to the user namespace so that
exit, exit(), quit or quit() are all valid ways to close the shell.
Call def: exit(self)
In [7]: type(exit)
Out[7]: IPython.core.autocall.ExitAutocall
它的定义如下所示:
class ExitAutocall(IPyAutocall):
"""An autocallable object which will be added to the user namespace so that
exit, exit(), quit or quit() are all valid ways to close the shell."""
rewrite = False
def __call__(self):
self._ip.ask_exit()
该self._ip.ask_exit()
调用运行此方法:
def ask_exit(self):
""" Ask the shell to exit. Can be overiden and used as a callback. """
self.exit_now = True
所以它实际上并没有退出 IPython,它只是在控制返回到 IPython 提示符时设置一个退出标志。