This is my folder structure:
src/
__init__py
Lowlevel/
__init__.py
ModuleToCheck.Py
Test/
__init__.py
ModuleToCheck_test.py
(__init__.py
are empty files)
Now I want to import ModuleToCheck.py
in ModuleToCheck_test.py
How am I able to do this without appending anything to sys.path
?
Update:
from ..Lowlevel import ModuleToCheck
leads to:
src$ python Test/ModuleToCheck_test.py
Traceback (most recent call last):
File "Test/ModuleToCheck_test.py", line 6, in <module>
from ..Lowlevel import ModuleToCheck
ValueError: Attempted relative import in non-package
The following is from http://docs.python.org/tutorial/modules.html#intra-package-references
You're running your module
ModuleToCheck_test.py
as the main module, hence the exception.One solution is to create a
test.py
module in yoursrc
directory containing the following:You can then run that module using
python test.py