[Python-Dev] PEP 382: Namespace Packages
andrew at acooke.org
Thu Apr 2 22:14:14 CEST 2009
Chris Withers wrote:
> Martin v. Löwis wrote:
>> I propose the following PEP for inclusion to Python 3.1.
>> Please comment.
> Would this support the following case:
> I have a package called mortar, which defines useful stuff:
> from mortar import content, ...
> I now want to distribute large optional chunks separately, but ideally
> so that the following will will work:
> from mortar.rbd import ...
> from mortar.zodb import ...
> from mortar.wsgi import ...
> Does the PEP support this? The only way I can currently think to do this
> would result in:
> from mortar import content,..
> from mortar_rbd import ...
> from mortar_zodb import ...
> from mortar_wsgi import ...
i may be misunderstanding, but i think you can already do this.
in lepl i have code spread across many modules (equivalent to your
mortar.rbd, i have lepl.matchers etc). then in lepl/__init__.py i import
those and define __this__ to export them into the lepl namespace. so you
can import either do:
from lepl import Literal
from lepl.matchers import Literal
and you get the same code.
i copied this from sqlalchemy, but i am sure other packages do something
similar. it's described in the python docs.
More information about the Python-list