Running an interactive interpreter inside a python

R. Bernstein rocky at panix.com
Wed May 14 23:31:04 EDT 2008


The next release of pydb will have the ability to go into ipython from
inside the debugger. Sort of like how in ruby-debug you can go into
irb :-)

For ipython, this can be done pretty simply; there is an IPShellEmbed
method which returns something you can call. But how could one do the
same for the stock python interactive shell?

To take this out of the realm of debugging. What you want to do is to
write a python program that goes into the python interactive shell -
without having to write your own a read/eval loop and deal with
readline, continuation lines, etc.

The solution should also allow
 - variables/methods in the calling PYthon program to be visible
   in the shell
 - variables set in the interactive (sub) shell should persist after the shell 
   terminates, although this is a weaker requirement. POSIX subshells
   for example *don't* work this way.

There has been much written about how to embed Python from C, so I
suppose this may offer one way. And at worst, I could write
a C extension which follows how C Python does this for itself.

But is there a simpler way?

Thanks.






More information about the Python-list mailing list