My Project looks like this:
├─outer_module
│ │ __init__.py
│ │
│ └─inner_module
│ a.py
│ b.py
├─test.py
__init__.py
:
from outer_module.inner_module import a
from outer_module.inner_module import b
a.py
:
instance_a = 1
b.py
:
instance_b = 1
print("instance_b created!")
test.py
:
from outer_module.inner_module import a
I want to shorten import path in test.py
, i.e. use from outer_module import a
. That is not unusual when I turn my project into a release module. But using __init__.py
, it will automatically invoke b.py
and print instance_b created!
. Seperating a.py
and b.py
from inner_module is not recommended because they are functionally similar. Other .py file may invoke b.py
so b.py
must appear in __init__.py
Could anyone give some advice?