eval in embed Python
Urban Velkavrh
urban at slo.net
Sun Oct 3 20:06:56 EDT 1999
Hi,
I am having problems evaluating compiled code object in embed python. The
problem seems to be in PyEval_GetGlobals() which always returns NULL.
Compiling my test code with and without thread support gives same result.
The test code (inside C++'s main()):
Py_Initialize();
initextension();
PyRun_SimpleString("import sys\n");
PyRun_SimpleString("import extension\n");
struct _node*pn=PyParser_SimpleParseString("x=extension.returnone();\nprint
x;",Py_single_input ) ;
PyCodeObject*pco=PyNode_Compile( pn, "test.pyc");
PyNode_Free(pn);
PyObject *globals=PyEval_GetGlobals(); <<<< the problematic function
returns NULL
PyObject * result=PyEval_EvalCode(pco, globals, globals ); <<< eval code
doesn't work because globals==NULL
Py_DECREF(pco);
Py_DECREF(result);
I am new in Python so this approach might be totally wrong. Please correct
me.
Regards,
Urban
More information about the Python-list
mailing list