Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python.announce > #191
| From | Tomer Filiba <tomerfiliba@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python.announce |
| Subject | Nimp: Nested Imports (a la Java) |
| Date | 2011-06-16 01:48 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <mailman.35.1308250982.1164.python-announce-list@python.org> (permalink) |
Nimp (Nested Imports) is a little meta-importer hook for Python 2.3-2.7 and 3.0-3.2 that enables the use of *nested packages* (`com.ibm.foo.bar`), as is commonplace in Java and various other languages. It works by collecting all packages that begin with a common prefix on your `sys.path` and "merging" them into logical packages.
Homepage: http://pypi.python.org/pypi/nimp
Install: pip install nimp
Example
-------
Consider the following package layout (say, under site-packages, or anywhere on your python path):
site-packages/
com-ibm-storage/
... package files ...
com-ibm-storage-plugins/
... package files ...
com-google-protobuf/
... package files ...
com-google-appengine/
... package files ...
Using Nimp is easy:
import nimp
nimp.install()
You can place these two lines in your `site.py`; after calling `nimp.install()`, the following imports will "magically" work:
import com # a namespace package (empty)
import com.google.protobuf
import com.ibm.storage
from com.ibm.storage.plugins import MySQLPlugin
Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread
Nimp: Nested Imports (a la Java) Tomer Filiba <tomerfiliba@gmail.com> - 2011-06-16 01:48 -0700
csiph-web