[Python-Dev] closure semantics

Guido van Rossum guido at python.org
Tue Oct 21 20:19:40 EDT 2003


> > Walter suggested 'global.x = 23' which looks reasonable; unfortunately
> > my parser can't do this without removing the existing global statement
> > from the Grammar: after seeing the token 'global' it must be able to
> > make a decision about whether to expand this to a global statement or
> > an assignment without peeking ahead, and that's impossible.
> 
> Couldn't this be solved by making 'global<whitespace>.' a token?
> 
> Should {get|has}attr(global, 'foo') be possible?

Yes, I think if we go this path, global should behave as a predefined
variable.  Maybe we should call it __globals__ after all, consistent
with __file__ and __name__ (it would create a cycle, but we have
plenty of those already).

Though I still wish it didn't need underscores.  Maybe 'globals' could
sprout __getattribute__ and __setattr__ methods that would delegate to
the current global module?

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list