bug in python's scope handling?
Tim Peters
tim.one at home.com
Wed Jul 18 15:15:23 EDT 2001
[Philipp Weinfurter, on "a = a + 1", or some such]
> ...
> i don't mean to be pedantic, but the rules are that if a variable
> is not found in local scope, then the compiler looks up the global
> scope and python doesn't follow this rule here.
Except you made that rule up <wink>. The actual rule is that if a name is
bound anywhere within a code block, that name is local throughout the entire
code block. This determination is made at compile-time, not at runtime. In
"a = a + 1", a is bound to within the code block, therefore all instances of
"a" within the code block refer to a (the same) local vrbl.
More information about the Python-list
mailing list