Interactive loop with InteractiveInterpreter

Michael Chermside mcherm at mcherm.com
Fri Apr 4 13:43:56 EST 2003


> Hmm replying to myself here but I just figgured out a way that maybe is
> good... or bad... ad an extra layer before I call
> 
>     InteractiveInterpreter.runcode()
> 
> If I am about to send a for statement or a while statement to the
> interpreter I skip that line and set up my own loop with the parameters from
> the the loopline and then feed each line to the interpreter several times,
> handling the looping myself.

If ALL you have to handle is the code:

    for i in list:
        print i

Then I think you can probably "set up your own loop". But I hope you
realize that this doesn't generalize very well. If you had this:

    x = 1
    while complexFunc(x):
        x = doFirstThing(x)
        x = doSecondThing(x)

Then I'd be VERY surprised if you could "set up your own loop" --
basically you'd have to write your own python interpreter!

Fortunately, are correct that looking at debugging hooks is the
way to go for what I _think_ you want. (I think you want an interactive
display that stops after each "line" of code, right?) Whether or
not that's done via debuggermodule, I'm not sure, but if you explore
the docs a little and still have questions, I'm sure others here can
answer them.

-- Michael Chermside





More information about the Python-list mailing list