[Python-Dev] Relative imports in Py3k
g.brandl at gmx.net
Sat Sep 25 15:52:10 CEST 2010
Am 25.09.2010 15:15, schrieb anatoly techtonik:
> I wonder if situation with relative imports in packages is improved in
> Python 3k or we are still doomed to a chain of hacks?
> My user story:
> I am currently debugging project, which consists of many modules in one package.
> Each module has tests or other useful stuff for debug in its main
> section, but it is a
> disaster to use it, because I can't just execute the module file and
> expect it to find
> relatives. All imports are like:
> from spyderlib.config import get_icon
> from spyderlib.utils.qthelpers import translate, add_actions, create_action
> PEP 328 http://www.python.org/dev/peps/pep-0328/ proposes:
> from ... import config
> from ..utils.qthelpers import translate, add_actions, create_action
> But this doesn't work, and I couldn't find any short user level
> explanation why it is
> not possible to make this work at least in Py3k without additional magic.
Uh, "this doesn't work" is a report that every developer loves. I suppose
Python does raise an exception with a message?
For diagnosing this, you should also at least include from which module
you're trying to executing these import statements.
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-Dev