Intra-package References?? (again)

M

marcroy.olsen

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.html#SECTION008420000000000000000
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
 
R

Ron Adam

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.html#SECTION008420000000000000000
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top