How do I structure subdirectories in a python project, and make the code therein available to other subdirectories within the same project?
Example of what I'm finding difficult:
root/
+--- __init__.py
+--- foo/
+--- __init__.py
+--- foo.py
+--- test/
+--- foo_test.py
I have tried to use relative imports (as suggested in this SO answer)
In foo_test.py
:
#!/usr/bin/python
from ... import foo
Attempting to run this from the command line:
$ chmod +x ./foo_test.py
$ ./foo_test.py
I get the following error:
Traceback (most recent call last):
File "./foo_test.py", line 3, in <module>
from ... import foo
ValueError: Attempted relative import in non-package
Question:
What is the pythonic way to make foo
available to foo_test
and other subdirectories which sit alongside foo
?