![](https://secure.gravatar.com/avatar/0b854fe5258eb97b09ae8f914ab9d598.jpg?s=120&d=mm&r=g)
Quoth the Samuele Pedroni:
In particular, a global statement contained in an exec statement does not affect the code block containing the exec statement, and code contained in an exec statement is unaffected by global statements in the code containing the exec statement.
I think this is broken. As long as we're going to allow exec-with-1-arg to implicitly mess with the current namespace, names in the exec'ed statement should have the same meanings as they do in the surrounding statically-compiled code.
So, global statements in the surrounding scope should be honoured in the exec'ed statement, and global statements should be disallowed within the exec'ed statement.
Better still, get rid of both exec-with-1-arg and locals() altogether...
That's my plan, so I suppose we should not bother to "fix" the broken behavior that has been around from the start. --Guido van Rossum (home page: http://www.python.org/~guido/)