Structure of packages

Ben Fisher jamon.ben at gmail.com
Wed Jan 9 15:07:16 EST 2008


I am trying to learn the best way to do intra-package references. My
package looks like this:

PackageName
    __init__.py
    /a
        __init__.py
       a.py
        ...
    /b
        __init__.py
        ...
    /c
        __init__.py
        ...
    /d
        __init__.py
        ...
I have layered the dependencies so that a depends on b, b depends on
c, and c depends on d. There are no circular references.

Now I would like to be able to refer to the subpackage b from inside
the subpackage a. In effect, I would like to say "from '../b' import
*"

I had thought that "from PackageName.b import *" would work. This
works for a file in the directory /PackageName, but not for a file in
the directory /PackageName/a.  It's like when you are running a Python
file in the directory /PackageName/a it doesn't know about PackageName
- No module named "PackageName".

Is there a solution to this, or a better way to structure the directories?



More information about the Python-list mailing list