embedding

Bruce Dodson bruce_dodson at bigfoot.com
Fri Aug 6 14:08:04 EDT 1999


>But, if you mean: "How can I create an object in the global namespace?"
>That is slightly different; for this you can use PyEval_GetGlobals().

>This returns a dictionary, on which you can then use
>PyDict_GetItemString() and PyDict_SetItemString().


BUT PyEval_GetGlobals will return null it it is not called from within
Python.  This will never be the case when extending Python, but when Python
is embedded, it may happen.  This is because PyRun_* define the global
scope, so if you're not somehow inside a PyRun_ thing (e.g. module called
from python called from embedder), there are no globals.

In an embedded-python situation, if you decide that all of your PyRun_*
calls are going to use __main__ as the global namespace,
PyModule_GetDict(PyImport_AddModule("__main__")) will do it.





More information about the Python-list mailing list