Q: Caller's frame, was: Re: Q: Interactive input

Jan Kybic Jan.Kybic at epfl.ch
Tue Nov 7 10:11:12 CET 2000


On 24 Oct 2000, Jan Kybic wrote:

> Hi,
> 	would there be a simple way to stop the execution of a script,
> read commands from the keyboard and  execute them in the current
> frame? Something like keyboard() in Matlab. I know you can do it using
> the debugger, but this still requires a lot of typing: import pdb,
> pdb.run('adsdas') , b , c , ...
> 
> I would just like to put 'keyboard()' somewhere in my script, be able
> to examine and change the values of some variables, perhaps call some
> functions, and continue.

Kalle Svenson wrote:

>I suppose you could use a loop with calls to raw_input() and
>exec(), like:
>...stuff...
>while 1:
>    cmd = raw_input("cmd: ")
>    if not cmd:
>        break
>    exec(cmd)
>...more stuff...

OK, thanks. But how do I make a function out of it? Imagine I want to
replace the five lines above with a call to one function, keyboard().
In this function, how do I retrieve the caller's frame, to pass it to
exec, so that it has access to the variables at the level where
keyboard() was called from? I looked in the documentation and could
not find anything, so I would be grateful for any pointers. 

Thanks,
	Jan



-- 
-------------------------------------------------------------------------
Jan Kybic <Jan.Kybic at epfl.ch>      BIG IOA DMT EPFL Lausanne, Switzerland
       or <kybic at ieee.org>         tel. work +41 (21) 693 5142
For PGP key see my WWW page.       http://bigwww.epfl.ch/kybic



More information about the Python-list mailing list