PyRun_SimpleString error handling
Randy Heiland
heiland at ncsa.uiuc.edu
Tue Jun 6 10:09:49 EDT 2000
I'm trying to figure out how to detect/return an error when using
PyRun_SimpleString.
Here's my simple pgm:
#include <Python.h>
#include <import.h>
#include <graminit.h>
#include <pythonrun.h>
void main()
{
char save_error_type[1024], save_error_info[1024];
PyObject *errobj, *errdata, *errtraceback, *pystring;
int retval;
Py_Initialize();
retval = PyRun_SimpleString("print foo");
printf("retval (from PyRun_SimpleString) = %d\n",retval);
PyErr_Fetch (&errobj, &errdata, &errtraceback);
if (errobj != NULL) printf("errobj != NULL\n");
else printf("whoops -- errobj == NULL\n");
}
You guessed it - I get the "whoops", the errobj is NULL.
Can someone enlighten me?
--Randy
More information about the Python-list
mailing list