I have the following package structure (drastically simplified from a real use case):
mypackage/
├── __init__.py
├── mod1.py
│ ├── def func1(): return 1
│ └── ...
│
├── mod2.py
│ ├── def func2(): return 2
│ └── ...
└── mod3.py
with __init__.py
like this
from .mod1 import *
from .mod2 import *
Now, in mod3.py
I want to access the packages complete namespace with one alias like res = p.func1() + p.func2()
and I want this to achieve this by one relative import statement. Is this possible?
I don't want an absolute import like import mypackage as p
(because the code should be indifferent on renaming the package).
Note, this is related to but different from this unanswered question from 2009.
mod1
andmod2
) and I don't want to keep track of which name comes from which module. – Destination