[C++-sig] Embedded Python

Craig Slusher cslush at gmail.com
Fri Jun 27 23:58:43 CEST 2008


I am having trouble with the following code:

PyObject *module = PyImport_ImportModule(modulename);
if (module == NULL) {
    PyObject* et, *ev, *etr;
    PyErr_Fetch(&et, &ev, &etr);
    PyObject* traceback = PyImport_ImportModule("traceback");
    PyObject* tb = PyObject_CallMethodObjArgs(traceback,
PyString_FromString("format_exception"), et, ev, etr, NULL);
    char *message = PyString_AsString(PyObject_Str(tb));
    ...
    ...
}

When this code executes, it gets into the "module == NULL" condition.
However, when I try to get the exception that occurred, I get the
value "<NULL>" copied into the "char* message"  variable.

Can anyone shed some light on what might cause this to happen? I
thought that if I actually get into that NULL condition that an
exception has occurred.


-- 
Craig Slusher
cslush at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080627/44f37f9c/attachment.htm>


More information about the Cplusplus-sig mailing list