On Tue, Feb 24, 2009 at 11:20 AM, Ilya Roitburg <[email protected]> wrote:
> It would be possible if foo() was declared inside of func():
>
> def func():
> i=10
> def foo():
> print i
> foo()
>
That comes with a major caveat. In versions prior to Python 3, you
cannot assign to i. You would have to do something like this if you
want to assign:
def func():
i=[10]
def foo():
i[0] += 1
foo()
print i[0]
In Python 3, you have the 'nonlocal' statement that makes life better:
def func():
i=10
def foo():
nonlocal i
i += 1
foo()
print i
--
Jonathan Gardner
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---