[Python-Dev] Re: PEP 328 -- relative and multi-line import

Aahz aahz at pythoncraft.com
Fri Apr 9 11:42:52 EDT 2004


On Wed, Apr 07, 2004, Bill Janssen wrote:
>
> I really wish I'd been paying more attention to 328, which I've just
> read.  This proposal seems to break lots and lots and lots of existing
> code.  Maybe I'm reading it wrong.
> 
> I've written many, many packages that use the form
> 
>      import foo
> 
> where "foo" is a sibling module in the package.  

You won't be able to do that anymore.

> Or
> 
>       from foo import bar
> 
> where, again, foo is a sibling to the current module.  Packages that
> work like this have been submitted to on-line libraries, printed in
> books, etc., etc., etc.

You'll have to change these to

    from .foo import bar

> I really hope I'm reading the PEP wrong!  Am I correct in thinking
> that come Python 2.4 or 2.5, these will just break if the package
> isn't at the top level (reachable from sys.path)?

They won't break until Python 2.6.  Python 2.5 will issue a
DeprecationWarning when it finds relative imports.

> I was thinking (some months ago) that y'all would come up with an
> absolute form instead, something like
> 
>       from / import os

Nope.  Absolute imports are the most common form, and we do want to
encourage absolute imports whenever possible (because of the conflicts
with the stdlib).  Relative imports should be "marked".
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?



More information about the Python-Dev mailing list