title: Why doesn't exec work in a function with a subfunction?
body: <p>It looks like you can't use exec in a function that has a subfunction...</p>
  
  <p>Anyone know why this Python code doesn't work?  I get an error at the exec in test2.  Also, I know exec's aren't good style, but trust me, I'm using exec for an appropriate reason. I wouldn't use it otherwise.</p>
  
  <pre><code>#!/usr/bin/env python
  #
  
  def test1():
      exec('print "hi from test1"')
  
  test1()
  
  def test2():
      """Test with a subfunction."""
      exec('print "hi from test2"')
      def subfunction():
          return True
  
  test2()
  </code></pre>
  
  <p>EDIT: I narrowed down the bug to having a function in a subfunction. It has nothing to do with the raise keyword.</p>