how to do "load script; run script" in a loop in embedded python?
gagsl-py2 at yahoo.com.ar
Mon Apr 7 08:00:08 CEST 2008
En Thu, 03 Apr 2008 20:52:31 -0300, <lipingffeng at gmail.com> escribió:
> Hi, all,
> I am currently involved in a project that needs to load/run a python
> script dynamically in a C application. The sample code is as
> PyObject *LoadScript(char *file, char *func)
> PyObject *pName, *pModule, *pDict, *pFunc;
> pName = PyString_FromString(file);
> pModule = PyImport_Import(pName);
> pDict = PyModule_GetDict(pModule);
> pFunc = PyDict_GetItemString(pDict, func);
> return pFunc;
Remember to check all PyObject* return values, NULL means there was an
And pay attention to reference counts! Read the section about reference
counts in both books, Extending and Embedding, and the Python API
> The first loop is perfectly ok, but on the second loop, script loading
> is successful but running will always fail.
"fail" in what form? A Python exception? The program freezes? A core dump?
More information about the Python-list