I am developing a library in python3x and I'm having some trouble trying to import all modules, classes and functions.
/example.py
/math/
__init__.py
linalg.py
solve() #inside module.py
The issue here is that I would like to simply be able to import my library inside example.py and then use all functions defined inside the different modules as numpy does, for example:
import math as m
m.solve()
instead of using
import math as m
m.linalg.solve()
or
import math.linalg as m
m.solve()
How should I define __init__.py to include everything this way. I've tried using dir(linalg), absolute imports, etc by I can't get my head around it.
Thx.
SOLUTION:
At the end what I did was create a wrapping layer inbetween to hide the module dependency.
Inside the __init__.py:
from .linalg import *
from .wrappers import *
then created a wrappers.py along with linalg.py:
from math.linalg import solve
def wrapper_solver():
{
solve()
}
and then in example.py:
import math as m
m.wrapper_solver()
Hope it helps someone.