D
djw
I'm sturcturing my (relatively) large application into packages and am
having trouble understanding one aspect of module/package paths.
If I have a structure like:
in /:
appA.py
__init__.py
in X/:
modX1.py
modX2.py
__init__.py
in Y:/
modY1.py
__init__.py
Now, if I do the following imports and run appA.py, all is well:
in appA.py:
from X import modX1
import Y.modY1
in modX1:
import modX2
in modY1: (as long as run from appA.py)
import X.modX1
But, if I try to create a test harness inside modY1 (in an if statement
checking __name__ with "__main__") and run modY1.py with the last import
(import X.modX1), I get an ImportError.
So, the question is, how do you import into a sub-package to allow both
a script at the root level to import the module ("library mode") and for
the module itself to run in "test harness" mode with the same import?
Any hints appreciated.
-Don
having trouble understanding one aspect of module/package paths.
If I have a structure like:
in /:
appA.py
__init__.py
in X/:
modX1.py
modX2.py
__init__.py
in Y:/
modY1.py
__init__.py
Now, if I do the following imports and run appA.py, all is well:
in appA.py:
from X import modX1
import Y.modY1
in modX1:
import modX2
in modY1: (as long as run from appA.py)
import X.modX1
But, if I try to create a test harness inside modY1 (in an if statement
checking __name__ with "__main__") and run modY1.py with the last import
(import X.modX1), I get an ImportError.
So, the question is, how do you import into a sub-package to allow both
a script at the root level to import the module ("library mode") and for
the module itself to run in "test harness" mode with the same import?
Any hints appreciated.
-Don