I have a python project, I divided it into two parts, a library part and a
binary part.
For organization reasons, I wanted to have a hierarchy like this:
project/
lib/
__init__.py
module1.py
module2.py
bin/
binary1.py # contains: import module1
binary2.py # contains: import module2
doc/
...
The problem is, of course, the simple import in binary{1,2}.py doesn’t work, at
least in the coding phase (before installation).
Any suggestions? How do you test your code when you’re coding?
I use absolute imports everywhere.
Setting PYTHONPATH to the directory above
project, you can importmodule1frombinary1.pylike this:The
__init__.pyfiles can make importing simpler, let’s say in each file you have a class. Usually you would have to import the class like this (inclduding filename):But if you edit
lib/__init__.pyto contain this line:You can use the namespace of
libto importModule1directly fromlib: