(Serious?) package namespace problem (and a proposal)

Bjorn Pettersen bjorn at roguewave.com
Wed Jun 28 20:53:17 EDT 2000


Gordon McMillan wrote:
> Sean Blakey wrote:
> >On Wed, Jun 28, 2000 at 09:56:27PM +0000, Huaiyu Zhu wrote:
> [snip]
> >OK, I think I see what you mean.  You are objecting to the way that
> >python searches first for modules in the local directory before
> >searching the normal PYTHONPATH, correct?
> 
> >If you don't want python to search the current directory for imports,
> >there is a very simple solution: put this snippet above all of your
> >other imports: import sys
> >sys.path.remove('.')
> 
> Not a real solution. If module x is part of a package, and does an "import
> y", then the package is searched first. This has nothing to do with  '.'
> being on sys.path. It's called a "relative import", and it means that if
> you have "package.os", then the real "os" is unavailable anywhere in
> "package". Period.
> 
> I think the "relative import" feature should be shot in the head (2 posts
> today), but unfortunately most packages rely heavily on it.

Well, I get the problem too now (bang my head hard enough and I'll
eventually understand ;-)

The relative import feature probably should be "shot in the head", but
since it's in use (and presumably useful), how do we go about loading
the global modules?

The current suggestions are "import magicroot.os" and "import .os". I
don't like either, but would probably prefer the first since it is more
explicit...

-- bjorn




More information about the Python-list mailing list