En Thu, 03 Apr 2008 20:52:31 -0300, <[EMAIL PROTECTED]> 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
> following:
>
> 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  
error.
And pay attention to reference counts! Read the section about reference  
counts in both books, Extending and Embedding, and the Python API  
Reference. http://docs.python.org/

> 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?

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to