[Python-3000] Should package __init__ files include pkgutil.extend_path?
M.-A. Lemburg
mal at egenix.com
Tue Sep 9 23:26:34 CEST 2008
On 2008-09-06 23:06, skip at pobox.com wrote:
> I'm trying to figure out how to install this dbm.sqlite module I have
> without overwriting the basic install. My thought was to create a dbm
> package in site-packages then copy sqlite.py there. That doesn't work
> though. Modifying dbm.__init__.py to include this does:
>
> import pkgutil
> __path__ = pkgutil.extend_path(__path__, __name__)
>
> I'm wondering if all the core packages in 3.x should include the above in
> their __init__.py files.
If all you want to do is get the module into the dbm package, why not
make this explicit by requiring an import to install the extra module ?!
import install_dbm_sqlite
which then does:
import sys, dbm
import dbm_sqlite
# Install dbm_sqlite into the dbm package
sys.modules['dbm.sqlite'] = dbm_sqlite
dbm.sqlite = dbm_sqlite
Unlike pkgutil, this also works with ZIP files and frozen modules
and makes the installation explicit and visible to the user reading
your code.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Sep 09 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-3000
mailing list