triphook triphook - 1 month ago 9x
Python Question

Predefined module aliases in Python?

I'm developing a library of Python modules that is fairly deeply nested, e.g.:


Is there some way to define aliases for the modules ahead of time (maybe by modifying, so that instead of importing with...

from MyTools.HydroTools.Code import hydro
from MyTools.TerraTools.Code import terra

...I could do something cleaner like

from MyTools import hydro, terra


You want to push these nested packages on top of your module namespace.

In MyTools/ add:

from .HydroTools.Code import hydro
from .TerraTools.Code import terra