Magic Module Methods?

Skip Montanaro skip at pobox.com
Sun Oct 21 11:04:34 EDT 2001


    >> [Magnus Lie Hetland]
    >> > I just found myself needing (or wanting) a module which could have
    >> > default values for variables that weren't set;
    >> 
    >> I expect it would be near-infinitely clearer if you simply set the
    >> module variables to their default values explicitly at module
    >> initialization

Let me suggest another reason __getattr__ might be useful for modules.
Suppose you had a package made up of lots of modules.  Instead of importing
all of those modules into the package when the package was imported, with
__getattr__ could you defer import until first access?

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list