Say i have this this structure.
MyApp
├── main.py
└── package
├── __init__.py
├── a.py
├── b.py
├── c.py
├── d.py
├── e.py
├── f.py
├── g.py
├── h.py
├── ...
└── z.py
And in main.py
I need to use all modules, from a.py
to z.py
I'd like to know how I can import all those modules with one import statement.
So instead of doing
from package import a
from package import b
...
from package import z
I could just import the package and have all the modules ready.
Things I've tried
import package
a = package.a.A()
# AttributeError: 'module' object has no attribute 'a'
Now I know I could put a code in __init__.py
to add all the modules to __all__
, but from what I've read, we should avoid 'from package import *'
The reason for this is that the package might have an increasing number of modules and I would like to adding an import statement to the main code each time a module is created. Ideally I'd like to be able to just drop the module in the package and have it ready for use.