C module calls python script: how to set exception in C

Alex new_name at mit.edu
Fri May 18 13:40:24 EDT 2001


> However, is it safe to call PyObject_Repr here, or can it itself err
> again?

Yes, you can get an error in the __repr__ method of a class, for
instance.  You may want something like

callable_repr = PyObject_Repr(callable_repr);
if (!callable_repr) { return NULL; }
PyErr_Format(PyExc_TypeError, "%s blah", callable_repr);

If it were me, I would probably just say that the callable passed to the
function returned the wrong type, and let the user figure out what that
was.

HTH
Alex.



More information about the Python-list mailing list