[Python-Dev] Relative import

Andrew Bennetts andrew-pythondev at puzzling.org
Wed Dec 17 22:16:45 EST 2003

On Wed, Dec 17, 2003 at 10:08:21PM -0500, Barry Warsaw wrote:
> On Wed, 2003-12-17 at 22:04, Andrew Bennetts wrote:
> > On Wed, Dec 17, 2003 at 09:33:43PM -0500, Barry Warsaw wrote:
> > > 
> > > That's why when I tend to think about this, I start wanting a way to
> > > spell "definitely give me the global one, no matter what".  IOW, I feel
> > > like I want a way to bypass relative module lookups.
> > 
> > Alternatively, maybe what you want is a way to say "definitely give me the
> > standard library one, no matter what", e.g.
> > 
> >     from stdlib import codecs
> Interesting.  I see the subtle distinction.  One searches only the
> standard library, the other searches every directory on sys.path.  I'm
> not sure I'd have much need to restrict the search to just the standard
> library.  Plus, would that include site-packages?

I should have been clearer.  What I'm basically proposing is to make
site-package called "stdlib", leaving a default python install with a very
uncluttered top-level namespace, thus reducing unexpected name conflicts.

Otherwise, this idea doesn't require any modification to import semantics,
except for some magic to make stdlib the default root for imports for
backwards compatibility.  Thinking about it a bit harder, though, I'm not
sure it's as easy as I initially thought, because this would then make
importing 3rd party packages not work, i.e. currently you can do:

    import urllib
    import pygtk

without problems, because they are both top-level.  If urllib moved into a
"stdlib" package, it's hard to imagine a clean way where old code that does
those two lines would still work.

I still like the idea of having the standard library in its own package,
but I guess that will have to wait until Python 3.0.


More information about the Python-Dev mailing list