Package question

Hans Nowak ivnowa at hvision.nl
Mon Sep 25 12:12:46 CEST 2000


Howdy y'all,

Not being a newbie, I do have some dumb questions... Disclaimer: I have
not been able 
to keep up with all the messages lately, due to the high volume of this
newsgroup, so
maybe some of them have been answered before and I just failed to notice
them. 

I will ask the Dumb Package Question here and save the others for a
separate message. :)

OK: What is the right way to use packages? I mean, apparently they are
only useful if you
have a bunch of (possibly related) modules, which are not dependent on
modules in other
packages.

For example, let's say I have a directory with modules called MyLib. Now
I want to
separate the Tkinter-specific modules in a package, let's call it TkLib,
which sits in
this same directory MyLib. This is not a problem as long as the modules
in TkLib do *not* use any module in MyLib, since there does not seem to
be a way to look for modules "one
package up". 

Of course one could argue that I should add MyLib to sys.path or
PYTHONPATH, so I can
always say "from MyLib import foo", from anywhere. This would work in
this case, but not
when I have a program with some modules in nested packages. E.g.

  myprogram.py
  MainPackage\
    a.py
    SubPackage1\
      b.py       
    SubPackage2\
      c.py

In such cases, b.py cannot find a.py and thus it cannot use any general
modules in
MainPackage. Neither can it see c.py in SubPackage2.

This situation makes packages virtually useless to me. Are there ways
around this that I
am not aware of, or am I just trying to use them in the wrong way?

Veel liefs,



More information about the Python-list mailing list