Suppose I have a script that does a lot of stuff, and doesn’t work well somewhere near the end. I’d love to be able to add a start_ipython() function at that point, which would stop the script at this point, and let me inspect variables and so on with ipython. How can I do this?
Suppose I have a script that does a lot of stuff, and doesn’t work
Share
Note that this has changed in IPython-0.11. Instead of what is described below, simply use the following import:
The answer below works for IPython versions prior to 0.11.
In the region where you want to drop into ipython, define this
and call
start_ipythonwhere you want to drop into the interpreter.This will drop you into an interpreter and will preserve the
locals()at that point.If you want a regular shell, do this
Check the documentation for the above functions for details. I’d recommend that you try the ipython one and if it throws an
ImportError, switch to normal so that it will work even if ipython is not installed.