preserving namespaces with sub-packages
gmcm at hypernet.com
Sun Dec 2 09:37:50 EST 2001
Kevin Altis wrote:
[that is, Button is a class in module widgie]
> framework directory
> various module files for the framework
> widgie directory
[but wants that referenced as framework.widgie.Button]
You have to hack widgie/__init__.py so that Button (and siblings)
are top-level attributes. Just be aware that when the programmer
has a problem with Button and goes looking for the code, it's not
going to be where he expects to find it.
> In addition, it would be nice have __init__.py automatically load all
> the files in the widgie directory rather than having to hard-code each
> filename. Hopefully I'm explaining the problem correctly. Any
> suggestions or solutions?
No you don't. You don't want button automatically loaded -
you want it to disappear!
Even without that namespace hackery, doing an "automatic load" of
submodules is a generally a poor idea - it makes for a very
expensive import. Perhaps the programmer only wanted one submodule,
yet he pays for all of them.
More information about the Python-list