I'm currently reading about Python's submodule in submodule imports and somehow I can't find a proper answer. Here is an example:
root/
main.py
moduleA/
__init__.py
log.py
moduleB/
__init__.py
worker.py
I'd like to import log
in worker
by using import moduleA.log
. And I'd like to import worker
in main
and use it there.
So far I've found the following solutions:
- Append
sys.path
with../
(sys.path.append('../')
) - I read something about using
pip -e
to install my module into the environment. - Avoiding scripts which import from submodules.
I've read that the sys.path
hack is considered the best practice. But somehow it feels wrong.
So I'd like to know what is considered best practice by you.