title: Python Eval executing environment
body: <p>I do not understand what environment a eval or exec statement executes in.  You can pass both global and local scopes to them but I don't quite understand what this means.  Does python create an anonymous module for them, and if that is the case how do the global and local scope differ?</p>
  
  <p>Does it run it like it was an anonymous function?  If that was the case the global and local scopes would make more sense to me, although would you still need to call <code>global var</code> to prevent python from making a local variable on assignment?</p>
  
  <p>And here is some code to show what I am actually trying to do.</p>
  
  <pre><code># module level vars
  result = ''
  
  allowed_builtins = {"__builtins__":{'int':int, 'str':str, 'range':range, 'dir':dir,
                                      'zip':zip
  },
                      "result":result}
  </code></pre>
  
  <p>In class</p>
  
  <pre><code>def _exec(self, answer, function_name, input):
      global result
      exec_string = answer + '\n'
      exec_string += 'global result; result = %s(%s)' % (function_name, input)
      exec exec_string in allowed_builtins, {}
  
      return result
  </code></pre>
  
  <p>I would like the var result in my scope to be able to be set from within the eval/exec's scope.</p>