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@gmail.com
Craig Slusher 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);
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.
This really has nothing to do with C++. I suggest you try comp.lang.python, where the C API experts hang out. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
I'll try that. Thanks On Fri, Jun 27, 2008 at 6:29 PM, David Abrahams <dave@boostpro.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);
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
Craig Slusher wrote: that if I actually get into that NULL condition that an exception has occurred.
This really has nothing to do with C++. I suggest you try comp.lang.python, where the C API experts hang out.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com _______________________________________________ C++-sig mailing list C++-sig@python.org <C%2B%2B-sig@python.org> http://mail.python.org/mailman/listinfo/c++-sig
-- Craig Slusher cslush@gmail.com
participants (2)
-
Craig Slusher -
David Abrahams