embedded Python sample

bruno Monnet monnetb at yahoo.com
Wed Sep 11 16:09:54 CEST 2002


Syver Enstad <syver-en+usenet at online.no> wrote in message news:<ur8g16aiw.fsf at online.no>...
> 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.

This sample looks great, but I'm coding for windows and the library
used by python for fopen is not compliant with the multithreaded lib
used by Visual 6.0 projects ...



More information about the Python-list mailing list