<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(&amp;et, &amp;ev, &amp;etr);<br>    PyObject* traceback = PyImport_ImportModule(<span class="literal">&quot;traceback&quot;</span>);<br>    PyObject* tb = PyObject_CallMethodObjArgs(traceback, PyString_FromString(<span class="literal">&quot;format_exception&quot;</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 &quot;module == NULL&quot; condition. However, when I try to get the exception that occurred, I get the value &quot;&lt;NULL&gt;&quot; copied into the &quot;char* message&quot;  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>