I have this structure:
.
└── module
├── __init__.py
└── submodule
├── __init__.py
├── foo.py
└── bar.py
In module.submodule.__init__.py I have this:
import foo
import bar
In module.submodule.foo.py I have this:
import very_heavy_third_party_module as vhtpm
...
I would like to import bar only, but I got slowed down by foo (let's imagine there is an ugly time.sleep(3) in both foo and module/__init__.py).
So my goal is to write this below without getting slowed down by other parts of my module:
from module.submodule.bar import saybar
saybar()
How can I just import saybar located in my submodule bar?
from datetime import datetime.now?__init__.pythat defines the package you import all submodules you always end up importing all submodules and there's nothing you can really do to avoid this. To fix this: avoid putting the imports inside__init__.py, or just put those that are fast and leave the heavy module non-imported.