PEP 328: Imports: Multi-Line and Absolute/Relative

Anders J. Munch andersjm at dancontrol.dk
Wed Mar 10 09:46:18 EST 2004


"Aahz" <aahz at pythoncraft.com> wrote:
> 
>     from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text
>         LEFT, DISABLED, NORMAL, RIDGE, END)

+1

> Here are the contenders:
> 
> * One from Guido::
> 
>       from .foo import
>
>   and ::
> 
>       from ...foo import

+1

I presume 
   from ..sibpack import amod
will import from a sibling package; a common need.

IMO relative imports should be preferred over absolute imports. An
absolute import is sort of like a global variable. Relative imports
should require minimal effort and look good.

It has been argued that the dot is too small and easily overlooked.
However, it is replacing something that's _completely_ invisible, and
I haven't heard at lot of complaints about that.  And if the dot-count
is off it's not a big problem, you get an import error and fix it.

>The final option is to define an algorithm
>   for finding relative modules and packages; the objection here is
>   "Explicit is better than implicit".  (The algorithm proposed is
>   "search up from current package directory until the ultimate package
>   parent gets hit".)

-1. Too DWIM.

- Anders





More information about the Python-list mailing list