title: Why did Python 3 changes to exec break this code?
body: <p>I looked through the myriad 'Python exec' threads on SO, but couldn't find one that answered my issue. Terribly sorry if this has been asked before. Here's my problem:</p>
  
  <pre><code># Python 2.6: prints 'it is working'
  # Python 3.1.2: "NameError: global name 'a_func' is not defined"
  class Testing(object):
    def __init__(self):
      exec("""def a_func():
        print('it is working')""")
      a_func()
  
  Testing()
  </code></pre>
  
  <hr>
  
  <pre><code># Python 2.6: prints 'it is working'
  # Python 3.1.2: prints 'it is working'
  class Testing(object):
    def __init__(self):
      def a_func():
        print('it is working')
      a_func()
  
  Testing()
  </code></pre>
  
  <p>As the standard function definition works in both Python versions, I'm assuming the problem must be a change to the way exec works. I read the API docs for 2.6 and 3 for <code>exec</code> and also read the "What's New In Python 3.0" page and couldn't see any reason why the code would break.</p>