bug in python's scope handling?

Philipp Weinfurter philipprw at gmx.at
Wed Jul 18 14:48:02 EDT 2001


On Wed, 18 Jul 2001 14:20:49 -0400, Steve Holden <sholden at holdenweb.com> wrote:
> When your Python is compiled into bytecode, the assignment to a is detected
> during compilation of your function func2(). The name a is therefore assumed
> to refer to a local variable, hence the ruin-time exception you observe.

yes, this is what i thought. but is it correct?
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.
it doesn't really hurt, since in 99% of all cases the programmer
probably _thinks_ he is referring to a local variable, but still...



More information about the Python-list mailing list