Re: exec in a nested function yields an error

2009-01-13 Thread Scott David Daniels
TP wrote: ... > def f(): def f_nested(): exec "a=2" print a f() ... What is the problem? Why? What it wants is you to provide the "in context" portion of the exec statement. I expect the reason it fails is that there is no dictionary that is available as locals that encom

Re: exec in a nested function yields an error

2009-01-13 Thread Albert Hopkins
On Tue, 2009-01-13 at 16:13 +0100, TP wrote: > 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", l

exec in a nested function yields an error

2009-01-13 Thread TP
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 functi