simple? embedding question

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


sndive at gmail.com 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:
> http://service-spi.web.cern.ch/service-spi/external/Boost/1.30.0/rh73_gcc32/libs/python/doc/tutorial/doc/using_the_interpreter.html
> 
> 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.

-Farshid



More information about the Python-list mailing list