ByteCode Questions

Steven D. Majewski sdm7g at Virginia.EDU
Tue Aug 21 13:04:28 EDT 2001


Skip covered your question pretty thoroughly -- I'll just add that 
the hack below is no longer needed, as 2.1 has sys._getframe():

>>> print sys._getframe.__doc__
_getframe([depth]) -> frameobject

Return a frame object from the call stack.  If optional integer depth is
given, return the frame object that many calls below the top of the stack.
If that is deeper than the call stack, ValueError is raised.  The default
for depth is zero, returning the frame at the top of the call stack.

This function should be used for internal and specialized
purposes only.
>>> sys._getframe()
<frame object at 0x1e6590>

-- Steve Majewski



> import traceback
> 
> def EvalInCaller(Command):
>     try:
>         1/0
>     except:
>         import traceback
>         import sys
>         tb = sys.exc_info()[2]
>         ExecFrame = tb.tb_frame.f_back
>         exec(Command, ExecFrame.f_globals, ExecFrame.f_locals)





More information about the Python-list mailing list