Obtaining references to function objects on the execution stack from the frame object?

Posted by Marcin on Stack Overflow See other posts from Stack Overflow or by Marcin
Published on 2009-06-23T19:34:07Z Indexed on 2010/03/21 10:41 UTC
Read the original article Hit count: 299

Filed under:
|
|

Given the output of inspect.stack(), is it possible to get the function objects from anywhere from the stack frame and call these? If so, how?

(I already know how to get the names of the functions.)

Here is what I'm getting at: Let's say I'm a function and I'm trying to determine if my caller is a generator or a regular function? I need to call inspect.isgeneratorfunction() on the function object. And how do you figure out who called you? inspect.stack(), right? So if I can somehow put those together, I'll have the answer to my question. Perhaps there is an easier way to do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about inspect