triphook triphook - 1 year ago 130
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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download