By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,698 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,698 IT Pros & Developers. It's quick & easy.

Embedded Python Import problem

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Jun 27, 5:47*pm, sleek <csl...@gmail.comwrote:
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));
* * ...
* * ...

}
Jun 28 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.