title: Eval scope in Python 2 vs. 3
body: <p>I came across bizarre eval behavior in Python 3 - local variables aren't picked up when eval is called in a list comprehension.</p>
  
  <pre><code>def apply_op():
      x, y, z = [0.5, 0.25, 0.75]
      op = "x,y,z"
      return [eval(o) for o in op.split(",")]
  print(apply_op())
  </code></pre>
  
  <p>It errors in Python 3:</p>
  
  <pre><code>▶ python --version
  Python 3.4.3
  ▶ python eval.py
  Traceback (most recent call last):
    File "eval.py", line 7, in &lt;module&gt;
      print(apply_op())
    File "eval.py", line 5, in apply_op
      return [eval(o) % 1 for o in op.split(",")]
    File "eval.py", line 5, in &lt;listcomp&gt;
      return [eval(o) % 1 for o in op.split(",")]
    File "&lt;string&gt;", line 1, in &lt;module&gt;
  NameError: name 'x' is not defined
  </code></pre>
  
  <p>And it works fine in Python 2:</p>
  
  <pre><code>▶ python --version
  Python 2.7.8
  ▶ python eval.py
  [0.5, 0.25, 0.75]
  </code></pre>
  
  <p>Moving it outside of the list comprehension removes the problem.</p>
  
  <pre><code>def apply_op():
      x, y, z = [0.5, 0.25, 0.75]
      return [eval("x"), eval("y"), eval("z")]
  </code></pre>
  
  <p>Is this intended behavior, or is it a bug?</p>