O
OKB (not okblacke)
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
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