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

Andrew Clover and-google at doxdesk.com
Mon Mar 15 04:52:33 EST 2004


Dieter Maurer <dieter at handshake.de> wrote:

> This will break lots of code...

That's why it's a __future__ option.

> 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.

But it's not just used in packages, where the filenames of sibling
modules are known. There may be scripts in directories with many
unrelated files, for which relative importing would be highly
undesirable (or even, in a directory where someone other than the
owner has write-access, a possible security risk).

> Relative imports are essential to enhance locality.

Sure. But we need to separate relative and absolute imports. The status
quo is inconsistent (sometimes it's relative, sometimes it's not) and
trips people up. Making the current syntax do an absolute rather than a
relative import is a good choice because:

  - in general, absolute imports are used more often;

  - a proper relative import mechanism requires the ability to 'go up'
    which can't currently be done, so we'd be inventing new syntax for
    it anyway.

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Python-list mailing list