[Python-ideas] Relative import of self or parent package?
C Anthony Risinger
anthony at xtfx.me
Thu Apr 6 11:53:16 EDT 2017
I occasionally want to do something like this:
import .. as parent
or:
import . as self
The pattern is a little less useful for namespace packages (which I've been
trying to use almost exclusively, along with relative imports) than it is
for __init__.py based packages, but there is still some utility.
Is there a reason one can't import dots directly and bind them to a name? I
did not find any text around this and the closest I've come up with is:
from .. import __name__ as parent_module_name
parent = __import__(parent_module_name)
Could we support relative imports without `from` so long as there is an
`as`?
Thanks,
--
C Anthony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170406/ecafa191/attachment.html>
More information about the Python-ideas
mailing list