In Python, is it possible to define an alias for an imported module?
For instance:
import a_ridiculously_long_module_name
...so that is has an alias of 'short_name'.
Join Stack Overflow to learn, share knowledge, and build your career.
In Python, is it possible to define an alias for an imported module?
For instance:
import a_ridiculously_long_module_name
...so that is has an alias of 'short_name'.
import a_ridiculously_long_module_name as short_name
also works for
import module.submodule.subsubmodule as short_name
from normal_module import super_duper_ridiculously_long_function_name as supe
?
– Lou
Feb 2 at 14:38
from name import X
(after the alias definition) I get No module named name
. Can we import modules from aliases?
– Amelio Vazquez-Reina
Jan 23 '13 at 21:07
If you've done:
import long_module_name
you can also give it an alias by:
lmn = long_module_name
There's no reason to do it this way in code, but I sometimes find it useful in the interactive interpreter.
Yes, modules can be imported under an alias name. using as keyword. See
import math as ilovemaths # here math module is imported under an alias name
print(ilovemaths.sqrt(4)) # Using the sqrt() function
from MODULE import TAGNAME as ALIAS