interactive program execution

Fernando Perez fperez528 at yahoo.com
Thu Feb 6 13:05:24 EST 2003


Axel Grune wrote:

> Hi, is it posible switch into the interactive mod during the execution
> of a program? For example you have a console program and you want to
> debug or test it. You execute it and at a specific point it switches
> in the interactive mod of the interpreter and you can check variables
> or call functions by hand.

IPython (http://www-hep.colorado.edu/~fperez/ipython/) has this built in, 
here's a simple example:

# IPython embedded shell for interactive debugging
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()

....

# then anywhere in your code:

ipshell()   # starts up an embedded shell with access to locals/globals

The manual has all the details and more/fancier examples.

Cheers,

f.

ps. I hope people don't get annoyed at my pitching of ipython for these 
tasks, but these questions seem to prop up quite frequently and many of 
ipython's features were driven exactly by this need.  Maybe one day we'll 
have them in the standard library as one liners...




More information about the Python-list mailing list