[Python-ideas] descriptors outside of classes

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 31 03:52:33 CEST 2011


Eric Snow wrote:
> Of course, the application of all this would be to let a module control 
> what happens when another module tries to use the first module's 
> namespace.

BTW, if anyone's wondering about use cases for this, I have
one in PyGUI where the top-level module auto-imports names
from submodules the first time you refer to them. This
avoids the overhead of loading modules that an application
doesn't use, without requiring the user to memorise which
names come from which submodules. It also gives me the
flexibility to move things around between submodules if
I want.

This is currently done using a custom module subclass
with a __getattr__ method. Although I'm thinking about
using a different strategy, because the current one
confuses the heck out of py2app and py2exe. :-(

-- 
Greg



More information about the Python-ideas mailing list