Magic Module Methods?
David Bolen
db3l at fitlinxx.com
Mon Oct 22 15:11:30 EDT 2001
Skip Montanaro <skip at pobox.com> writes:
> 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?
Although you can already do this today via other mechanisms. For
example, the LazyModule class used by the mx packages - an instance is
assigned in the main module __init__ to each submodule name. Then as
a class instance, it does get the __getattr__ call at which point it
imports the child module and then loads its dictionary into its own
instance.
Also, a downside to any of the "lazy" schemes is that they tend to do
a nice job of confusing packaging tools such as py2exe and installer.
--
-- David
--
/-----------------------------------------------------------------------\
\ David Bolen \ E-mail: db3l at fitlinxx.com /
| FitLinxx, Inc. \ Phone: (203) 708-5192 |
/ 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
\-----------------------------------------------------------------------/
More information about the Python-list
mailing list