Fix Python – Can you define aliases for imported modules in Python?

Question

Asked By – Jordan Parmer

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’.

Now we will see solution for issue: Can you define aliases for imported modules in Python?


Answer

import a_ridiculously_long_module_name as short_name

also works for

import module.submodule.subsubmodule as short_name

This question is answered By – vartec

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0