Author arigo
Recipients
Date 2004-08-07.21:59:38
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=4771

The behavior you get can be explained quite easy, but it seems nevertheless inconsistent with the documentation: in my opinion it is a serious bug.

The reason the "exec"ed code doesn't work like the same code put at the global module level is that code that runs at the module level always runs with the same dictionary for its globals and locals, whereas in your example you use two different dictionaries.

Assignments always go to the locals; that's why 'y' goes into the dictionary 'e'.  Now a function can only see its own locals and the surrounding globals; that's why execfunc() misses the value of 'y'.  This is the old way Python worked.  In recent versions, a special trick was added so that functions defined inside another function find variable bindings from the enclosing function.  I think you found a case where this trick fails to apply.
History
Date User Action Args
2007-08-23 14:23:41adminlinkissue991196 messages
2007-08-23 14:23:41admincreate