Embedded Python Import problem

Benjamin musiccomposition at gmail.com
Fri Jun 27 21:57:02 EDT 2008


On Jun 27, 5:47 pm, sleek <csl... at gmail.com> wrote:
> 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
PyObject_Str on NULL, you get "<NULL>."

>
>     char *message = PyString_AsString(PyObject_Str(tb));
>     ...
>     ...
>
> }




More information about the Python-list mailing list