Relative imports and "import X as Y"



I was looking at PEP 328. It says that relative imports with the
dot syntax will only be allowed with the "from" import variety (e.g.,
"from ..somemodule import somename"). The reason given for this in the
PEP is that after import xxx.yyy, "xxx.yyy" is usable in an expression,
but the leading period syntax is inconsistent with this (you can't use
".somepackage.somemodule" in an expression).

However, this reasoning doesn't apply to "import X as Y", as long
as Y is an ordinary name. As a few recent posts here have touched on,
there are actual differences between the "import X (as Y)" and "from X
import name" varieties, most notably that the second form binds name in
the importing namespace whereas the first does not.

So, will relative imports in Python 3.0 allow things like "import
...relative.importing.path as prettyname"? If not, why not?

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
.



Relevant Pages

  • Re: PEP 328: Imports: Multi-Line and Absolute/Relative
    ... I don't see the above syntax referenced in the PEP. ... listing specific names to import (that is, import foo as a bare term ... will always be an absolute import).""" ... I took this to mean that relative imports would require the "from ... ...
    (comp.lang.python)
  • PEP 328 update
    ... PEP 328 has been updated and is available at ... One area where feedback is ... particularly desired is on the frequency of relative imports inside ... both in absolute terms and as a percentage of ...
    (comp.lang.python)