simple? embedding question

Farshid Lashkari no at
Wed Oct 31 18:00:04 CET 2007

sndive at wrote:
> it works!
> could i cache maindict pointer in a global var or am i condemned to
> call
>                 PyObject* mainmod = PyImport_AddModule("__main__");
>                 assert(mainmod);
>                 PyObject* maindict = PyModule_GetDict(mainmod);
>                 assert(maindict);
> every time i want to PyRun_String?
> i call Py_Finalize only atexit.
> i also found boost library docs of some help:
> btw what kind of object is returned in case i use Py_file_input
> in PyRun_String?

Yes, you can keep a reference to maindict if you wish, but make sure you 
increment the reference count since PyModule_GetDict() returns a 
borrowed reference.


More information about the Python-list mailing list