Embedding: How to set globals for PyObject_Call

Jason Orendorff jason at jorendorff.com
Wed Feb 20 14:44:12 EST 2002


Scott Gilbert wrote:
> I dove through the code, and it appears that I need to setup a
> PyFrameObject to be associated with my PyThreadState.  I wasn't able
> to figure out how to do that though.
> 
> As you can see in my example below, I have the globals sitting right
> there.  I just don't know how to tell Python that those are the
> appropriate globals while invoking PyObject_Call(...).  A similar
> problem occurs when evaluating "globals", "locals", "dir", or
> functions that call those.

Really?  The part about "functions that call those" sounds a bit off.
I thought Python functions that call globals() would work.
Each Python function contains a pointer to its globals namespace
(the fn.func_globals attribute), and calling a Python function
creates a PyFrameObject.  It seems as though it should work.

So, what are you really trying to do?  :)  I have a feeling that
calling vars() directly from C is a mistake; there's probably an
easier way to do what you need.

For example, if you just want to look at module's namespace,
that's easy:

  result = PyModule_GetDict(module);

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list