Is it possible to tell a python script to stop at some point and give you a hand interactively, for example with ipython?

Suppose I have a script that does a lot of things and doesn't work well somewhere near the end. I would like to add a function start_ipython()to this point that would stop the script at that point, and let me check the variables, etc. Using ipython. How can i do this?

+5
source share
2 answers

Note that this has changed in IPython-0.11. Instead of what is described below, just use the following import:

from IPython import embed as shell

Below is the answer for IPython versions prior to 0.11.


In the area where you want to switch to ipython, define this

def start_ipython():
   from IPython.Shell import IPShellEmbed
   shell = IPShellEmbed()
   shell()

start_ipython, .

locals() .

,

def start_python():
   import code
   code.interact()

. . ipython, ImportError, , , ipython .

+15

- . , , :

import pdb; pdb.set_trace()

pdb, .

ipdb , easy_install, .

+6

All Articles