<pre style="font-family: arial,sans-serif;" class="code" id="codemain">I am having trouble with the following code:<br><br>PyObject *module = PyImport_ImportModule(modulename);<br><span class="keyword">if</span> (module == NULL) {<br>
PyObject* et, *ev, *etr;<br> PyErr_Fetch(&et, &ev, &etr);<br> PyObject* traceback = PyImport_ImportModule(<span class="literal">"traceback"</span>);<br> PyObject* tb = PyObject_CallMethodObjArgs(traceback, PyString_FromString(<span class="literal">"format_exception"</span>), et, ev, etr, NULL);<br>
<span class="keyword">char</span> *message = PyString_AsString(PyObject_Str(tb));<br> ...<br> ...<br>}<br><br>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.<br>
<br>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.<br></pre><br>-- <br>Craig Slusher<br><a href="mailto:cslush@gmail.com">cslush@gmail.com</a>