In Python, how to drop into the debugger in an except block and have access to the exception instance? : <p>I'm trying to do something similar to the following:</p>

<pre><code>try:
    1/0
except ZeroDivisionError as e:
    import ipdb; ipdb.set_trace()
</code></pre>

<p>When I drop into the debugger, I'd like for the exception instance <code>e</code> to be in my local scope. However, if I run this script, I find that this is not the case:</p>

<pre><code>Kurts-MacBook-Pro-2:Scratch kurtpeek$ python debug_exception.py
--Return--
None
&gt; /Users/kurtpeek/Documents/Scratch/debug_exception.py(4)&lt;module&gt;()
      2         1/0
      3 except ZeroDivisionError as e:
----&gt; 4         import ipdb; ipdb.set_trace()

ipdb&gt; dir()
['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__return__', '__spec__', 'ipdb']
ipdb&gt; e
*** NameError: name 'e' is not defined
</code></pre>

<p>Why is <code>e</code> not defined? I'm currently using <code>print</code> statements to find out the attributes of <code>e</code>, but I feel this should be possible to do interactively.</p>
