Can you define aliases for imported modules in Python?

Can you define aliases for imported modules in Python?

import a_ridiculously_long_module_name as short_name

also works for

import module.submodule.subsubmodule as short_name

Check here

import module as name

or

from relative_module import identifier as name

Can you define aliases for imported modules in Python?

If youve done:

import long_module_name

you can also give it an alias by:

lmn = long_module_name

Theres no reason to do it this way in code, but I sometimes find it useful in the interactive interpreter.

Leave a Reply

Your email address will not be published.