[python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?

M.-A. Lemburg mal at egenix.com
Fri Feb 18 22:35:35 CET 2011


Brett Cannon wrote:
> It says they are "highly discouraged" because "absolute imports are
> more portable and usually more readable", but now that people have had
> a chance to use explicit relative imports, do people still believe
> this? I mean if we truly believed this then why did we add the syntax?
> I know I have used it and love it, let alone that I don't buy the
> portability argument.

Let's put it this way: I think that PEP 8 gets way too much
attention in Python land.

It describes one way of doing things, but is not a bible or
strict style guide (and even says that).

Regarding relative imports: I think they were only added to
be able to port code that uses Python2-style imports (which
are relative as first try, then absolute) gradually to
code that uses absolute imports.

In all our larger projects we use absolute imports and this
has often helped in organizing the code, finding definitions,
etc. So far, we've not had any use for relative imports, but
I can imagine some uses for e.g. plugin modules and component
architectures that can be dropped into existing Python packages.
Relative imports can also help porting code when doing package
structure changes, e.g. moving top-level modules into a
package.

--
Marc-Andre Lemburg


More information about the python-committers mailing list