Inheriting Python modules?

Jeff Shannon jeff at ccvcorp.com
Tue Dec 18 13:45:57 EST 2001


Timo Linna wrote:

> Hi,
>
> How should "dynamic module inheritance" be implemented with Python?
>
> Example:
>
> It should be possible to write: "import defaults" so that it would first
> import everything from common.defaults -module and after that other stuff
> from product.defaults-module. Content of both modules should be accessible
> through one common (defaults) interface so that the caller wouldn't have to
> know from which module the code is actually accessed.

This is untested, but ISTM that if, inside your defaults.py, you import the
other module(s) using "from othermodule import *", it will have the effect you
want.  (I'm pretty sure that wxPython, at least, uses this technique.)  Of
course, you'll have to be careful to not cause any namespace conflicts amongst
your modules.  This is, however, one of the few legitimate uses of "from module
import *" (IMHO).

Jeff Shannon
Technician/Programmer
Credit International






More information about the Python-list mailing list