Re: [Tutor] nonlocal variables
2010/2/23 Hugo Arts > On Tue, Feb 23, 2010 at 1:38 PM, Vladislav Vorobyov > wrote: > > #!/usr/bin/python > > def func_outer(): > > x = 2 > > print('x is', x) > > def func_inner(): > > nonlocal x > > x = 5 > > func_inner() > > print('Changed local x to', x) > > > > func_outer() > > > > Output: > > File "nonlocal_var.py", line 6 > > nonlocal x > > ^ > > SyntaxError: invalid syntax > > Why? Cannon find in google it. > > > > check your python version. The nonlocal keyword is only supported in python > 3.x > > Hugo > O! Thank. I'm reading "Byte of Python". Didn't look about what version of python is it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] nonlocal variables
On Tue, Feb 23, 2010 at 1:38 PM, Vladislav Vorobyov wrote: > #!/usr/bin/python > def func_outer(): > x = 2 > print('x is', x) > def func_inner(): > nonlocal x > x = 5 > func_inner() > print('Changed local x to', x) > > func_outer() > > Output: > File "nonlocal_var.py", line 6 > nonlocal x > ^ > SyntaxError: invalid syntax > Why? Cannon find in google it. > check your python version. The nonlocal keyword is only supported in python 3.x Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] nonlocal variables
#!/usr/bin/python def func_outer(): x = 2 print('x is', x) def func_inner(): nonlocal x x = 5 func_inner() print('Changed local x to', x) func_outer() Output: File "nonlocal_var.py", line 6 nonlocal x ^ SyntaxError: invalid syntax Why? Cannon find in google it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor