Using IPython from the Python shell like `code.interact()`

我的未来我决定 提交于 2021-02-06 08:41:34

问题


Is it possible to use the IPython shell from an existing Python shell, as a shell-inside-a-shell, similarly to the built-in code.interact()?


回答1:


The recommended way of embedding IPython works fine:

~ $ python
Python 2.7 [...]
>>> from IPython.Shell import IPShellEmbed
>>> ipshell = IPShellEmbed()
>>> ipshell()

In [1]: 



回答2:


In IPython 0.11 the API has been overhauled and the shell is even easier to invoke:

import IPython

IPython.embed()



回答3:


Django manage.py shell invoke a IPython shell when possible, and it's implemented like this:

import IPython

shell = IPython.Shell.IPShell()
shell.mainloop()


来源:https://stackoverflow.com/questions/3423741/using-ipython-from-the-python-shell-like-code-interact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!