global variable not seen (bug?)

Bengt Richter bokr at oz.net
Wed Jan 8 14:33:32 EST 2003


On Wed, 8 Jan 2003 18:25:56 +0100, Michal Vitecek <fuf at mageo.cz> wrote:
[...]
>
> i must say that this behaviour is pretty strange (non-intuitive at
> least). why is it that the function looks for that variable in the
> scope of its module? wouldn't that be more intuitive if it looked for
> the variable in the current global scope?

"current" from what point of view ;-) When you're inside the function,
looking outwards sees enclosing lexical scopes, out to the file, which
is the module scope. Other ways of looking for names are possible, but
huge unstructured global name spaces are not a good idea.

Regards,
Bengt Richter




More information about the Python-list mailing list