I am changing a bunch of old Python code that sometimes runs in name collisions between packages. I have a question about when to use absolute import and whether it will be correct to import modules of only one level by name.
/package/ /package/__init__.py /package/subA /package/subA/__init__.py /package/subA/moduleA.py /package/subA/moduleB.py /package/subB /package/subB/__init__.py /package/subB/moduleA.py /package/subB/moduleB.py
Should each import statement in a package look like this:
import package.subX.moduleX
or
from package.subX import moduleX
How about in the __init__.py subpackage files. It would be wrong to just put
import moduleA import moduleB
Or, in /package/subA/moduleA.py, it would be wrong to just put:
import moduleB
python import
user297250 Apr 27 '11 at 22:35 2011-04-27 22:35
source share