[Python-Dev] Lexical scoping in Python 3k
Neil Schemenauer
nas at arctrix.com
Sat Jul 1 17:41:29 CEST 2006
Ka-Ping Yee <python-dev at zesty.ca> wrote:
> Most other languages that support lexical scoping (including Scheme,
> JavaScript, Ruby, Perl, E, Java, Smalltalk) provide a uniform way
> to read and write to scopes at all levels. This is done by letting
> programmers specify the scope in which they want a variable bound
> (usually with a keyword like "var" in JavaScript, "my" in Perl, or
> "define" in E).
That's not the Python way, IMO. I think the right way (assuming we
actually want to allow it) is to introduce a pure assignment
statement in addition to the assignment/declaration statement that
we already have. For example:
a = 1
def f():
b = 2
a := 2
def g():
b := 3
print a, b, c
g()
f()
would print "2 3 4". The := would assign but not declare a variable
in the current scope.
Neil
More information about the Python-Dev
mailing list