Package organization: where to put 'common' modules?

Kent Johnson kent at
Sat Mar 4 13:49:43 CET 2006

fortepianissimo wrote:
> Say I have the following package organization in a system I'm
> developing:
> A
>  |----B
>  |----C
>         |----D
> I have a module, say 'foo', that both package D and B require. What is
> the best practice in terms of creating a 'common' package that hosts
> 'foo'? I want to be able to
> - Testing modules in D right in D's directory and testing modules in B
> in B's directory;
> - If possible, minimize the modification to PYTHONPATH or sys.path
> while doing the above.

What I do is run always from the base directory (violates your first 
requirement). I make a util package to hold commonly used code. Then B 
and D both use
   from util import foo

In Python 2.5 you will be able to say (in D, for example)
   from ..util import foo


More information about the Python-list mailing list