[Python-Dev] Lexical scoping in Python 3k (original) (raw)
Andrew Koenig ark at acm.org
Sat Jul 1 21:06:38 CEST 2006
- Previous message: [Python-Dev] Lexical scoping in Python 3k
- Next message: [Python-Dev] Lexical scoping in Python 3k
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message: [Python-Dev] Lexical scoping in Python 3k
- Next message: [Python-Dev] Lexical scoping in Python 3k
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]