embedding python -- windows specify problems

Fredrik Lundh fredrik at pythonware.com
Thu Oct 5 11:55:08 CEST 2006


John Pye wrote:

> I have been working on some new code that embeds python in an C
> application. The embedding is working fine under Linux but crashing
> under Windows (XP) when I reach the following step.
>
> PyRun_AnyFile(f,name);
>
> If there's some python exception being thrown by the PyRun_AnyFile call,
> how can I retrieve it from C?
>
> Even when the file (f) being run by Python contains only a 'print'
> statement, the application still crashes on WinXP.

the contents and the layout of the FILE structure isn't defined, so PyRun_AnyFile()
only works if you make sure to open the file using *exactly* the same run time library
as Python itself uses.

it's usually easier to hand the problem over to the interpreter:

    PyRun_SimpleString("execfile('myscript.py')\n");

the same approach can be used to implement custom error handling, stdout/stderr
redirects, etc.

</F> 






More information about the Python-list mailing list