Embedded Python Import problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sleek

    Embedded Python Import problem

    I am having trouble with the following code:

    PyObject *module = PyImport_Import Module(modulena me);
    if (module == NULL) {

    PyObject* et, *ev, *etr;
    PyErr_Fetch(&et , &ev, &etr);
    PyObject* traceback = PyImport_Import Module("traceba ck");
    PyObject* tb = PyObject_CallMe thodObjArgs(tra ceback,
    PyString_FromSt ring("format_ex ception"), et, ev, etr, NULL);

    char *message = PyString_AsStri ng(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.
  • Benjamin

    #2
    Re: Embedded Python Import problem

    On Jun 27, 5:47 pm, sleek <csl...@gmail.c omwrote:
    I am having trouble with the following code:
    >
    PyObject *module = PyImport_Import Module(modulena me);
    if (module == NULL) {
    >
        PyObject* et, *ev, *etr;
        PyErr_Fetch(&et , &ev, &etr);
        PyObject* traceback = PyImport_Import Module("traceba ck");
        PyObject* tb = PyObject_CallMe thodObjArgs(tra ceback,
    PyString_FromSt ring("format_ex ception"), et, ev, etr, NULL);
    This is probably failing and returning NULL; When you call
    PyObject_Str on NULL, you get "<NULL>."
    >
        char *message = PyString_AsStri ng(PyObject_Str (tb));
        ...
        ...
    >
    }

    Comment

    Working...