Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:

I agree that it is confusing; in short: a bare exec() does not play well with 
closures;  
This is a consequence of the python execution model, and is unlikely to change.

Here, the class 'foo' is stored in the function's local variables.
But the execution of the body of the 'bar' class searches names in its local 
scope (the 
class body) and the global scope (the module level), and misses the function's 
locals...

I strongly suggest to avoid pure exec() statements; always specify a global 
and/or a 
local dictionary.

In your case, the following works:

def doExec(text):
  d = {}  # or:   d = dict(globals())
  exec text in d
  print d.keys()

----------
nosy: +amaury.forgeotdarc
resolution:  -> wont fix
status: open -> closed

_______________________________________
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4381>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to