PyRun_SimpleString error handling

Gordon McMillan gmcm at
Tue Jun 6 21:15:19 CEST 2000

heiland at (Randy Heiland) wrote in 
<393D062D.8413AC36 at>:

>I'm trying to figure out how to detect/return an error when using

As the Python/C API Reference Manual, Section 2. The Very High Level Layer 

int PyRun_SimpleString (char *command) 
Executes the Python source code from command in the __main__ module. If 
__main__ does not already exist, it is created. Returns 0 on success or -1 
if an exception was raised. If there was an error, there is no way to get 
the exception information. 

In other words, PyRun_ stuff is pretty much only good for side effects. If 
you want to get results or poke around, you have to get your hands dirty.

>Here's my simple pgm:
>#include <Python.h>
>#include <import.h>
>#include <graminit.h>
>#include <pythonrun.h>

BTW, only the first include is required.

- Gordon

More information about the Python-list mailing list