embedded Python sample

Syver Enstad syver-en+usenet at online.no
Tue Sep 10 19:05:18 CEST 2002


monnetb at yahoo.com (bruno Monnet) writes:

> Hi,
> 
> I'm trying to call a python script from my c++ code. All I need is to
> invoke the script and check the return status.
> 
> does anyone has a simple example ? All I found until now is very
> complex and ugly code :-((

I think something like this will do (untested)

void runPythonFile(char* myfile)
{
FILE* fileptr = fopen(myfile, 'r'); 
Py_Initialize();
int result = PyRun_SimpleFile(fileptr, myfile);
Py_Finalize();
return result;
}

You should get some ideas by reading the Extending/Embedding section
in the python manual, and then read the relevant sections the Python/C api.




-- 

Vennlig hilsen 

Syver Enstad



More information about the Python-list mailing list