From: Tim Chase on
> I'm curious, in an academic sense, if it's possible to spawn the
> interactive interpreter (>>>) in a running python application. Ideally, I
> would like to be able to access the modules, functions and variables the
> application can.
>
> Is something like this possible?

While not exactly "the interactive interpreter", you can use pdb
to drop to a debugging prompt where you can "access the modules,
functions and variables the application can". The common idiom
is to insert a line like

import pdb; pdb.set_trace()

in your code to have a break-point stop execution at the
designated point and leave you at a prompt where you can explore.

-tkc


From: Gabriel Genellina on
En Sat, 12 Dec 2009 02:11:27 -0300, Horace Blegg <tkjthingone(a)gmail.com>
escribi�:

> I wonder if I could cook something up with PyRun_SimpleString("import
> pdb;
> pdb.set_trace()"). This bears investigation!

pdb is a debugger, and provides a lot more than you're looking for, I
presume.
You may want to look at the code [1] and cmd [2] modules too.

[1] http://docs.python.org/library/code.html
[2] http://docs.python.org/library/cmd.html

--
Gabriel Genellina

From: Lie Ryan on
On 12/12/2009 3:49 PM, Tim Chase wrote:
>> I'm curious, in an academic sense, if it's possible to spawn the
>> interactive interpreter (>>>) in a running python application. Ideally, I
>> would like to be able to access the modules, functions and variables the
>> application can.
>>
>> Is something like this possible?

you can also use the -i switch to start the interactive interpreter once
the script reaches execution:
$ python -i myprogram.py
program output
>>> # names that are not been deleted at the end of program execution
>>> # can be accessed here
>>>