[Python-3000] replace globals() and global statement with global builtin object

BJörn Lindqvist bjourne at gmail.com
Mon Jul 3 16:14:20 CEST 2006


> > cache = None
> > def init():
> >     if not cache:
> >         pass
> >
> > Throws a NameError because cache is not declared in function init's
> > scope. So you would be forced to write:
> >
> > cache = None
> > def init():
> >     if not global.cache:
> >         global.cache = "foobar"
> >
> > I like the symmetry with self in classes. YMMV
>
> That can't work because imported names are also globals, as are
> classes and functions defined in the same module.

I... didn't think about that. Thanks for crushing my idea. :)

-- 
mvh Björn


More information about the Python-3000 mailing list