[Python-Dev] Lexical scoping in Python 3k
Andrew Koenig
ark at acm.org
Sat Jul 1 21:06:38 CEST 2006
> What about doing something similar to how import was changed?
>
> .a = 5 # this scope (self might be too magical
> ..a = 3 # up one scope
> ...a # up three
>
> Of course, this looks ... perhaps a bit strange. Also, counting is a
> bother.
I'd rather see a simpler rule: = never defines a variable in a surrounding
scope. If you want to affect the binding of such a variable, you have to
define it explicitly in the scope in which you want it.
Example:
x = 42
def f():
x = 123 # rebinds x as defined above
y = 123 # defines local variable
f()
print x # prints 123
print y # error -- y not defined
Yes, I know that rule is too simplistic. But I think I'd still prefer it to
the way things are now.
More information about the Python-Dev
mailing list