[Python-3000] The meaning of "global variable"

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Nov 3 03:19:33 CET 2006


Ka-Ping Yee wrote:
> Before it is reasonable to change the meaning of "global", we would
> need to have coherent answers to these questions:
> 
>     1.  What is the global namespace?

Under the proposal, there is no such thing as
"the" global namespace, so the question is
meaningless.

There's no such thing now, either -- there
are just (multiple) module-level namespaces.

>     2.  Do global variables belong to the global namespace?

Also meaningless as a corollary of 1.

>     3.  When it says "global x" does that mean x is a global variable?

Yes, from the point of view of the scope containing
the "global" declaration, it is. From the point of
view of a different scope, it might not be.

> Can you imagine trying to teach this?

With a few well-chosen examples, yes.

> either you have
> to say (#1) there is no longer such a thing as "the global namespace",

As I said, there isn't one now. Which namespace
is "the global namespace" depends on which module
you're looking from. Under the proposal, it would
depend on which scope you're looking from.

--
Greg


More information about the Python-3000 mailing list