exec in a nested function yields an error

TP Tribulations at Paralleles.invalid
Tue Jan 13 10:13:21 EST 2009


Hi everybody,

Try the following program:

####################
def f():
    def f_nested():
        exec "a=2"
        print a
f()
####################

It yields an error.
$ python nested_exec.py
  File "nested_exec.py", line 3
    exec "a=2"
SyntaxError: unqualified exec is not allowed in function 'f_nested' it is a
nested function

What is the problem?
Why?

Thanks

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)



More information about the Python-list mailing list