title: python pdb lambda function global name error
body: <p>I was testing a fix using <code>pdb.set_trace()</code> to make sure it worked the way I expected before implementing it and kept getting a weird error. </p>
  
  <pre><code>(Pdb) test = [1,2,3,4,4,3,2,1]
  (Pdb) max(range(len(test)),key=lambda i: test[i])
  *** NameError: global name 'test' is not defined
  </code></pre>
  
  <p>So I moved to my localmachine to make sure I could reproduce as simply as possible before asking for help. In ipython I get the exact same behavior.</p>
  
  <pre><code>In [1]: test = [1,2,3,4,4,3,2,1]
  
  In [2]: max(range(len(test)),key=lambda i: test[i])
  Out[2]: 3
  
  In [3]: import pdb; pdb.set_trace()
  --Call--
  &gt; /Users/tristanmatthews/anaconda/lib/python2.7/site-packages/IPython/core/displayhook.py(237)__call__()
  -&gt; def __call__(self, result=None):
  (Pdb) test = [1,2,3,4,4,3,2,1]
  (Pdb) max(range(len(test)),key=lambda i: test[i])
  *** NameError: global name 'test' is not defined
  </code></pre>
  
  <p>But at the normal command line it works just fine:</p>
  
  <pre><code>tristan:~$ python
  Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09) 
  [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; test = [1,2,3,4,4,3,2,1]
  &gt;&gt;&gt; max(range(len(test)),key=lambda i: test[i])
  3
  &gt;&gt;&gt; import pdb; pdb.set_trace()
  --Return--
  &gt; &lt;stdin&gt;(1)&lt;module&gt;()-&gt;None
  (Pdb) test = [1,2,3,4,4,3,2,1]
  (Pdb) max(range(len(test)),key=lambda i: test[i])
  3
  </code></pre>
  
  <p>If anyone has any idea what is going on here I would REALLY love to know.</p>
  
  <p>For the record the fix works fine in my code, just not in the debugger.</p>
  
  <p>For reference my versions of python are:
  Original error:</p>
  
  <pre><code>'2.7.3 (default, Apr 10 2013, 06:20:15) \n[GCC 4.6.3]'
  </code></pre>
  
  <p>Local Machine both ipython and the command line are the same:</p>
  
  <pre><code>In [5]: sys.version
  Out[5]: '2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09) \n[GCC 4.0.1 (Apple Inc. build 5493)]'
  &gt;&gt;&gt; sys.version
  '2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09) \n[GCC 4.0.1 (Apple Inc. build 5493)]'
  </code></pre>