Embedding Python in C/C++

kingcrustybun ericcoetzee at gmail.com
Wed Aug 9 11:25:33 EDT 2006


Not a Python newb but a bit out of my depth here...

We are trying to use the Python interpreter from within a C/C++
aplication to execute Python code which is in an external file. The
idea is to share a dictionary between the C app and the python script.
After Py_Initialize()

we do something like (ignoring checks)
p_module = PyImport_ImportModule("moduleX");
p_dict = PyDict_New();

Then, to add the dictionary we use
PyModule_AddObject(p_module, "dictName", p_dict);
Which fails.

I was expecting to see an empty dictionary called "dictName" in the
list of variables when i execute vars() in the imported python script.

Is the approach at least correct?




More information about the Python-list mailing list