Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment: Right. Nested scopes only work for statically compiled code; inside an 'exec' block, non-local variables are global.
In your case, I suggest to specify the context in which the code has to execute: x = 2 def f(): g = globals().copy() exec "x = 1\ndef b(): return x" in g print eval("b()", g) This prints 1, as you want it, and can still access names defined outside the f() function. And this gives you more control on the symbols available to the executed code. Python does something very similar when it loads a module. I don't think that this behaviour can ever change. Tentatively closing as "won't fix". ---------- nosy: +amaury.forgeotdarc resolution: -> wont fix status: open -> closed _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3963> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com