Problem embedding Python.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Oct 27 08:47:24 CET 2009


En Tue, 27 Oct 2009 03:25:54 -0300, Brandon Keown  
<keown.brandon at gmail.com> escribió:

> I am going to try to embed python in an application, but in simple
> testing, I could not get it to work.  The following code seems like it
> should work, but it crashes, and I have tried several things.  What
> could I be doing wrong?
>
> #include <Python.h>
>
> int main(int argc, char* argv[])
> {
> 	FILE* fp = fopen("test.py","r");
> 	Py_Initialize();
> 	PyRun_SimpleFile(fp,"test.py");
> 	Py_Finalize();
> 	return 0;
> }

Crashes, how? Try running inside a debugger to see where it crashes, or at  
least put a few printf.
You didn't test for the fopen result; are you sure "test.py" exists in the  
current directory at the time you run it?

-- 
Gabriel Genellina




More information about the Python-list mailing list