I'm basically attempting to do the same as the following question but i'm getting run time errors at the call to PyObject_Print
complaining about an error in "toupper() at 0x776e0226"
Python C API: Using PyEval_EvalCode
My code is:
int callExecFunction(const char* evalStr)
{
PyCodeObject* code = (PyCodeObject*)Py_CompileString(evalStr, "pyscript", Py_eval_input);
PyObject* global_dict = PyModule_GetDict(pModule);
PyObject* local_dict = PyDict_New();
PyObject* obj = PyEval_EvalCode(code, global_dict, local_dict);
PyObject* result = PyObject_Str(obj);
PyObject_Print(result, stdout, 0);
}
evalStr is "setCurrentFileDir()"
and pModule was initialized earlier from a script without error and was working as this code: http://docs.python.org/2/extending/embedding.html#pure-embedding.
And inside the loaded module there is the function:
def setCurrentFileDir():
print "setCurrentFileDir"
return "5"
What have I missed/done wrong in the eval function call. Note that I cannot call the function setCurrentFileDir "directly" through the python API, I must use eval.
Actually this works fine. However I had a .pyd file in the directory that python must have built (and eclipse was hiding from me) from an older run of the python script that didn't have the function defined, causing the problem.
Here is where I got the idea that the problem maybe a .pyd file.
python NameError: name '<anything>' is not defined (but it is!)