Developing modules with ‘pkgutil’

Peter Otten __peter__ at web.de
Thu Apr 16 04:39:39 EDT 2009


Ben Finney wrote:

> At this point I'm stuck. I can't see how to have the
> ‘docutils/__init__.py’ stop shadowing the names in the system-installed
> ‘docutils/__init__.py’, while still doing the namespace shuffle
> necessary to have my in-development module appear part of the wider
> package namespace. What should I be doing instead?

Weird idea. Try putting the following in your __init__.py files:

import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
__path__.reverse()
import __init__
globals().update(vars(__init__))
__path__.reverse()

If that doesn't work add

import docutils
docutils.__path__.insert(0, path_to_modified_version)

to your main script. Repeat for every subpackage.

Peter



More information about the Python-list mailing list