| Store | Cart

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

From: Dieter Maurer <die...@handshake.de>
11 Mar 2004 23:29:16 +0100
aahz at pythoncraft.com (Aahz) writes on 8 Mar 2004 15:24:56 -0500:
> ...> Rationale for Parentheses> =========================> > Currently, if you want to import a lot of names from a module or> package, you have to choose one of several unpalatable options:> > * Write a long line with backslash continuations::> >       from Tkinter import Tk, Frame, Button, Entry, Canvas, Text \>           LEFT, DISABLED, NORMAL, RIDGE, END

Why is this bad?

> * Write multiple ``import`` statements::> >       from Tkinter import Tk, Frame, Button, Entry, Canvas, Text>       from Tkinter import LEFT, DISABLED, NORMAL, RIDGE, END> > (``import *`` is *not* an option ;-)> > Instead, it should be possible to use Python's standard grouping> mechanism (parentheses) to write the ``import`` statement::

Do do not explain why.

> ...> Rationale for Absolute Imports> ==============================> > In current Python, if you're reading a module located inside a> package, it is not clear whether ::> >     import foo> > refers to a top-level module or to another module inside the package.> To resolve the ambiguity, it is proposed that ``foo`` will always be a> module or package reachable from ``sys.path``.

This will break lots of code...
I do not like it at all.

A package writer does know which external modules/packages he needs
and can avoid to use the name of one of these modules for his
own modules.

Relative imports are essential to enhance locality.
A package/module should in general not need to know
where it is located inside the package hierarchy to access
its subpackages.

We make extensive use of this locality:
We have myriads of Python packages which are essentially self contained
(apart from references to the standard library). To
avoid pollution of the Python path and name clashes, we
often organize them for concrete projects into folders.
To do this, the packages should not know where they are
located.

Recent Messages in this Thread
Aahz Mar 08, 2004 08:24 pm
John Roth Mar 09, 2004 01:04 am
Aahz Mar 10, 2004 10:49 am
John Roth Mar 10, 2004 01:04 pm
Stephen Horne Mar 10, 2004 04:44 pm
John Roth Mar 10, 2004 06:14 pm
Rocco Moretti Mar 17, 2004 07:11 pm
Stephen Horne Mar 09, 2004 01:09 am
Mike Mar 09, 2004 03:39 am
Josiah Carlson Mar 09, 2004 06:34 am
Sean Ross Mar 09, 2004 06:13 pm
Paul Rubin Mar 09, 2004 10:44 pm
Josiah Carlson Mar 10, 2004 04:20 am
Andrew Clover Mar 10, 2004 01:18 pm
Sean Ross Mar 10, 2004 03:11 pm
Josiah Carlson Mar 12, 2004 07:06 am
Thomas Heller Mar 09, 2004 07:41 am
Andrew Clover Mar 09, 2004 10:12 am
Denis S. Otkidach Mar 09, 2004 10:50 am
Gerrit Mar 10, 2004 11:41 am
Anders J. Munch Mar 10, 2004 02:46 pm
Dieter Maurer Mar 11, 2004 10:29 pm
Geoff Howland Mar 14, 2004 12:50 am
Andrew Clover Mar 15, 2004 09:52 am
Bernhard Herzog Mar 15, 2004 11:26 am
Aahz Mar 10, 2004 11:01 am
John Roth Mar 10, 2004 01:13 pm
Messages in this thread