If you want to refer to a module by using a different name, you can create an alias.
When a module is first imported, Python searches for the module and if found, it creates a module object 1, initializing it. If the named module cannot be found, a ModuleNotFoundError is raised. Python implements various strategies to search for the named module when the import machinery is invoked.
Having multiple version of a Python package/module/file is very common. Manipulating PYTHONPATH or using virtualenvs are a way to use various versions without changing your code.
In python programming, the second name given to a piece of data is known as an alias. Aliasing happens when the value of one variable is assigned to another variable because variables are just names that store references to actual value.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With