Embedded Python Import problem

S

sleek

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.
 
B

Benjamin

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);

This is probably failing and returning NULL; When you call
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top