471,356 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

Structure of packages

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?
Jan 9 '08 #1
1 1232
[Ben Fisher]
I am trying to learn the best way to do intra-package references.
IMO, the email package is a stellar example of best practices using
packages.

I have layered the dependencies so that a depends on b,
b depends on c, and c depends on d.
For the most part, I think packages tend to be over-used and can
create more problems than they solve. They were added as tool for
managing *very* large code bases and for helping resolve namespace
collisions between tools with similiar APIs. Your layering
application may also be a good use but I haven't seen packages used
that way before.
Raymond
Jan 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by DJ Majestik | last post: by
15 posts views Thread by Nick Coghlan | last post: by
2 posts views Thread by Peter Saffrey | last post: by
reply views Thread by Rich Burridge | last post: by
7 posts views Thread by Oliver Elphick | last post: by
reply views Thread by giovanni gherdovich | last post: by
13 posts views Thread by Rafe | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.