[Python-Dev] Re: Christmas Wishlist

Ken Manheimer klm at zope.com
Mon Dec 15 12:48:32 EST 2003

On Mon, 15 Dec 2003, Guido van Rossum wrote:

> > Barry Warsaw writes:
> >  > V <wink>. Explicit global imports.  I want a way to spell "import this
> >  > from the global standard library even if there's a this.py  in the local
> >  > directory".
> > 
> > I like the syntax:
> > 
> >     import global <dotted-name>
> > 
> > and
> > 
> >     from global <dotted-name> import <name>
> > 
> > Look Guido, no new keywords!  ;-)
> I'd much rather invent new syntax to spell *local* imports.  I like
>   from .module import something
> You can even generalize and write
>   from ..module import something
> to reference your package's parent package. :-)

As i've said before (though it's been a while) i think people want
this, it would be useful, and i think it would work well.

Barry wrote, in response to guido's message:

< Actually, if truth be told, I'd love to just ban local imports.  I
< understand that might be controversial though <wink>.

I don't understand the desire to totally prevent relative imports.  It
would be quite useful in avoiding growing module-naming problems,
where you have to be careful about shadowing a global module with one
in your package.

I *can* understand objecting to the ambiguity in the current
situation, where you don't know whether a module import will resolve
to a sibling module or one in higher up in the hierarchy.  That is why
i strongly prefer having a leading dot to explicitly signify a
relative import, and originally proposed it that way.  I expect that
the elimination of the ambiguity would mitigate the objection to
relative imports - and we would do away with the shadowing problems,
and even have easy relocation of modules, if there are cases where
software does need to move around.

klm at zope.com

More information about the Python-Dev mailing list