How to get a Function object from a Frame object
Gigi
gigi-s at bigfoot.com
Fri Apr 22 03:10:49 EDT 2005
Greg Ewing wrote:
> 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.
>
I can get the co_name and everything that's available from the code
object. However, I can't get to the actual function object. I need the
function object to get a custom function attribute that was injected
earlier as context. I didn't know that code objects could be shared. I
guess it really makes the whole thing impossible, unless the code object
kept a list of all the functions that share it. Thanks, anyway. I found
a different solution.
More information about the Python-list
mailing list