[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: embedding
From:       "Bruce Dodson" <bruce_dodson () bigfoot ! com>
Date:       1999-08-06 18:08:04
[Download RAW message or body]

>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.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic