I am trying to learn how to use the Python/C API correctly - all I actually need to do is to read a global variable (in my case dictionary - but I\'m starting with a simple
You should call PyObject_GetAttrString
on the result of PyImport_ImportModule
. I have no idea why you think that the __main__
module should define that variable:
PyObject *mod = PyImport_ImportModule("tryStuff");
PyObject *var1Py = PyObject_GetAttrString(mod, "var1");
You should also add the check on the results, since PyImport_ImportModule
can return NULL
when the import fails.