[docs] [issue25294] Absolute imports fail in some cases where relative imports would work

Nick Coghlan report at bugs.python.org
Wed Oct 7 05:52:06 CEST 2015


Nick Coghlan added the comment:

We seem to be talking past each other, so let's take a step back and ensure we have a common understanding of the absolute/relative terminology:

"import x.y.z" is an absolute import
"from x.y import z" is still an absolute import.
"from . import z" is an explicit relative import of a child or sibling module
"from .y import z" is also an explicit relative import

The relevant change in behaviour is between the "import x.y.z" form and the "from x.y import z" form due to the change in the way the related name binding (and name lookup in 3.5+) works, not between absolute and relative imports.

The relevant terminology to distinguish between "from ... import ..." vs "import ..." is just "from import" vs "non-from import", and there are definitely cases where from imports will work, but non-from imports will fail. That's not a style issue, it's a use-whichever-one-works for your code issue.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25294>
_______________________________________


More information about the docs mailing list