Package question

Bernhard Herzog herzog at online.de
Mon Sep 25 13:44:08 EDT 2000


Hans Nowak <ivnowa at hvision.nl> writes:

> Bernhard Herzog wrote:
> > 
> > Hans Nowak <ivnowa at hvision.nl> writes:
> > 
> > >   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.
> > 
> > Just use
> > 
> >         import MainPackage.a
> > 
> > and
> >         import MainPackage.SubPackage2.b
> 
> Yes, but that is exactly the problem... b.py cannot see MainPackage
> either. Unless I add it to sys.path, which I *don't* want to do. =(

But in myprogram.py "import MainPackage.a" works? IOW, is the directory
containing myprogram.py and MainPackage in sys.path? In most cases it's
automatically put into sys.path by the interpreter.

If that directory is in sys.path "import MainPackage.a" should work from
inside the package too.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list