I often find myself importing classes from modules that only differ in the last part of their namespace, e.g:
from a.b.c.d import Class1
from a.b.c.e import Class2
from a.b.c.f import Class3
Is there some way for me to type the common a.b.c. part just once?
I know that if they all had exactly the same namespace, i.e.
from a.b.c import Class1
from a.b.c import Class2
from a.b.c import Class3
Then I could just type
from a.b.c import (Class1, Class2, Class3)
So for my first example, I tried things like
from a.b.c import (d.Class1 as Class1,
e.Class2 as Class2,
f.Class3 as Class3)
... but that didn't work.
Any tips would be greatly appreciated.
If
ais one of your own packages (or if you willing and abale to maintain a fork...) you can use thea.b.cpackage as a facade:Then:
will work.