I am confused by why simple absolute imports do not work. Following the instructions of the Python packages , I have a package with one subpacket:
sound/
__init__.py
top.py
formats/
__init__.py
a.py
b.py
a.py contains:
def foo():
print("foo")
b.py contains:
from a import foo
def bar():
foo()
if __name__ == "__main__":
bar()
top.py contains:
from formats import b
if __name__ == "__main__":
b.bar()
Both files are __init__.pyempty. From sound / formats /, runs b prints fooas expected. But from the sound / when starting top, an error appears:
File ".../sound/top.py", line 1, in <module>
from formats import b
File "...\sound\format\b.py", line 1, in <module>
from a import foo
ImportError: No module named 'a'
(Note the strange appearance of the slashes in the first line and the backslashes in the second. Python 3.5, Windows 7 Pro.) It doesn't have to be that complicated - what syntax is needed to allow b to be sequentially imported
----- EDIT -----
unittest - , , . Python Project.