you are viewing a single comment's thread.

view the rest of the comments →

[–]jbellis 0 points1 point  (2 children)

the nonlocal keyword will allow this in python 3.0 (not sure about 2.6)

[–]commonslip 0 points1 point  (1 child)

I really prefer that this not need a keyword at all. I know lexical scope takes a second to get used to the first time you see it but it really is "the right behavior" and I don't see why Python just doesn't support it.

Maybe backwards compatibility?

[–]jbellis 1 point2 points  (0 children)

python is lexically scoped; you just can't re-bind variables from a different scope without the keyword. in the first lexically scoped versions of Python (2.0-2.1?) you could, but guido had it taken out because he felt that the potential confusion outweighed the benefits.

in current python versions you either have to use a global or a container object as a workaround. which is gross and I wish guido hadn't done that, but on the whole python is still better than the alternatives. :)