Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?)

Terry Reedy tjreedy at
Sun Aug 7 01:28:13 CEST 2005

"Paolino" <paolo_veronelli at> wrote in message 
news:42F4F2D3.80804 at
> seberino at wrote:
> I don't think the global keyword is useful actually.
> What's so special in a module nemespace to be priviledged like that.

The specialness of globals and locals was part of Python's original simple 
namespace design, and is still reflected in exec statements and eval 
functions, as well as in nested functions.

> The point IMO is accessing names defined somewhere in the enclosing
> namespaces.

Accessing such names is already possible, even *after* the outer function 
returns and the rest of its execution context is deleted.

> def enclosing():
>   var=2
>   def enclosed():
>     outer var=4

This is rebinding, rather than merely accessing.  Similar, but even more 
problematical would be initial binding in outer from inner:

def enclosing():
    def enclosed():
        outer var = 4

> this is the base of something useful.

Actually, it is the reinvention of classes:

class enclosing(object):
    def __init__(self):
        self.var = 2
    def enclosed(self):
        self.var = 4

There was a long discussion on the pydev list a couple of years ago re 
adding rebinding in addition to access (of outer variables).  I think, in 
the end, Guido concluded that there was no compelling reason, as of then, 
to add another general mechanism for private, sharable, rebindable 

> I think there is only one or none possible solution to an outer statement

There were lots of proposals for both the exact syntax and semantics of 
outer binding/rebinding.

Terry J. Reedy

More information about the Python-list mailing list