468,771 Members | 1,810 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Intra-package References?? (again)

Hi Python list,

I have been struggleling with this before, but have never been able to
find a good solution.
The thing I dont understand is, I follow the guide here:
http://docs.python.org/tut/node8.htm...00000000000000
And have the same setup as the packages howto here:http://
docs.python.org/tut/node8.html#SECTION008400000000000000000

But when I want to use Intra-package References, I need to put the
path to the packages explicit like this:
#sys.path.append('/path/to/pack/')
Before I can make import like this:
#from Sound.Effects import echo
from within the karaoke.py (just to stay with the tut)
If I print the sys.path from the same file, I can see that
#/path/to/pack/Sound/Filters/
is in the path.

Is there something that I completely is missing or could someone
please show me how, by example, how I use Intra-package References.

Best regards

Marc
Jan 29 '08 #1
1 3286


ma***********@gmail.com wrote:
Hi Python list,

I have been struggleling with this before, but have never been able to
find a good solution.
The thing I dont understand is, I follow the guide here:
http://docs.python.org/tut/node8.htm...00000000000000
And have the same setup as the packages howto here:http://
docs.python.org/tut/node8.html#SECTION008400000000000000000

But when I want to use Intra-package References, I need to put the
path to the packages explicit like this:
#sys.path.append('/path/to/pack/')
Before I can make import like this:
#from Sound.Effects import echo
from within the karaoke.py (just to stay with the tut)
If I print the sys.path from the same file, I can see that
#/path/to/pack/Sound/Filters/
is in the path.

Is there something that I completely is missing or could someone
please show me how, by example, how I use Intra-package References.

Best regards

Marc
If your package is in pythons path, all it should need is an empty
__init__.py file in the package and also in the sub package Filters also.
If your program is a stand alone program that may be installed someplace
not in pythons sys.path, then I've been using a some what different model.
I'm not sure what others think of it yet, but it's working well for me.

[karoki_program_dir] (may not be in pythons sys.path)
karoki.py
[lib]
[tests]
__init__.py
(unit tests here)
[filters]
__init__.py
(various filters here)
(other local modules/packages here)

And in karoki.py add the local lib directory to the front of sys.path
before your local module imports.

lib = os.path.abspath(os.path.join(__file__, '..', 'lib'))
sys.path.insert(0, lib)
This also makes sure it's the program location path, and not the current
console directory.
For running tests, I use a command line option.

python karoki.py --test
Cheers,
Ron



Jan 29 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Joey Tsai | last post: by
5 posts views Thread by Evan Smith | last post: by
7 posts views Thread by Komandur Kannan | last post: by
8 posts views Thread by JSC | last post: by
1 post views Thread by Laurence | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.