By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,596 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,596 IT Pros & Developers. It's quick & easy.

Re: is this a good way to do imports ?

P: n/a
Stef Mientki wrote:
hello,

I can't find any good documentation or examples of packages,
so I'm not sure if this is good / correct way, although it seems to work.

root
/ dir1
/ file1.py
/ general.py

/ dir2
/ file2.py

/ general_root.py

Now I want to be able to use functions of file2 in file1,
and vice-versa.
In practice the directory structure is more complex and nested more deeply,
and basically I want all modules to be reachable by all other modules.
One straightforward way is plain old absolute imports. Assume root is
in the import path (for instance, in site packages)
>
==== file1.py ====
import general
from root.dir1 import general
import file2
from root.dir2 import file2
or even
from root.dir2.file2 import func
This will break if the tree changes. So will new relative imports.
Pulling everything into root in its __init__.py breaks if there are
duplicate module names.

Anyway, above is what I am doing with my current 3-level
(pac.subpac.mod) package until I learn something really better, given
that the interdependencies in my package should remain relatively sparse.

tjr

Nov 5 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.