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
New submission from Kevin Fitch <[EMAIL PROTECTED]>:
codeText = """
class foo(object): pass
class bar(object):
baz = foo()
"""
def doExec(text):
exec text
### This works:
# Although if I do this before the doExec below, then the
# doExec doesn't fail.
# exec codeText
### But this does not: