packaging

andrew cooke andrew at acooke.org
Tue Mar 17 17:53:39 EDT 2009


Craig Allen wrote:
[...]
> Instead, I think we want "import package" to preserve the sort of
> namespace our loose python files provided, so:
>
>   import ourpackage
>   inst = ourpackage.OurClass()
>
> I think the way to do this, and it seems a legit use of a somewhat
> dangerous form of import, to in ourpackage's __init__.py do this:
>
>   from ourmodule import *
[...]

you can make that cleaner by using __all__ (so that you only expose what
you want to, and not everything that the "*" pulled in).

that is what i do, and i think it's normal behaviour.  see
http://docs.python.org/3.0/tutorial/modules.html#importing-from-a-package

for example, in my lepl parser -
http://www.acooke.org/lepl/api/lepl-pysrc.html

andrew




More information about the Python-list mailing list