Caller's frame, was: Re: Q: Interactive input
fredrik at effbot.org
Tue Nov 7 20:31:41 CET 2000
Jan Kybic wrote:
> 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.
throw an exception and examine the traceback stack (either
directly or via traceback.extract_tb()).
btw, the easiest way to accept commands is to use the stuff
in the code module:
import code, sys
frame = sys.exc_info().tb_frame.f_back
More information about the Python-list