C module calls python script: how to set exception in C
Harald Kirsch
kirschh at lionbioscience.com
Fri May 18 11:00:10 EDT 2001
In my C module I call user (i.e. programmer) supplied python callables
(i.e. those beasts defined with def) like
str = PyObject_CallObject(callable, args);
If callable fails, it sets the error indicator in the python
interpreter and I let my function return NULL. The net effect is a
nice stack trace denoting the place of failure in the python code
associated with the callable.
However, if the callable does not fail but return a value my function
is not happy with, i.e. it returns an integer object while it is
required to return a string, what is a good way to set up the error
indicator? I expect it to be like
PyErr_Format(PyExc_TypeError,
"%s returned wrong value",
PyObject_Repr(callable))
However, is it safe to call PyObject_Repr here, or can it itself err
again? (Ah, well and PyObject_Repr actually returns PyObject* and
needs to be converted.)
Harald Kirsch
--
----------------+------------------------------------------------------
Harald Kirsch | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172 | -- Paul Erdös
*** Please do not send me copies of your posts. ***
More information about the Python-list
mailing list