How to get a Function object from a Frame object

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Apr 20 01:39:08 EDT 2005


Steven Bethard wrote:
> Gigi wrote:
> 
>> I need access to a function object that corresponds to a frame object 
>> in a certain case from inside the function.
>
> Can you look up the code's co_name in the previous frame's locals?
> 
> You probably also need to check the previous frame's globals...  And 
> there are probably some cases where this code still wouldn't work...

Note that in general it's impossible to tell exactly
which function object was involved, since there could
be more than one function object sharing the same code
object, and the frame only references the code object.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list