PyRun_SimpleString error handling
Gordon McMillan
gmcm at hypernet.com
Tue Jun 6 15:15:19 EDT 2000
heiland at ncsa.uiuc.edu (Randy Heiland) wrote in
<393D062D.8413AC36 at ncsa.uiuc.edu>:
>I'm trying to figure out how to detect/return an error when using
>PyRun_SimpleString.
As the Python/C API Reference Manual, Section 2. The Very High Level Layer
says:
"""
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