在 Python 中,是否可以为导入的模块定义别名?
例如:
import a_ridiculously_long_module_name
...所以它有一个别名'short_name'。
在 Python 中,是否可以为导入的模块定义别名?
例如:
import a_ridiculously_long_module_name
...所以它有一个别名'short_name'。
import a_ridiculously_long_module_name as short_name
也适用于
import module.submodule.subsubmodule as short_name
如果您已经完成:
import long_module_name
你也可以给它一个别名:
lmn = long_module_name
没有理由在代码中这样做,但我有时发现它在交互式解释器中很有用。
是的,可以使用别名导入模块。用作关键字。看
import math as ilovemaths # here math module is imported under an alias name
print(ilovemaths.sqrt(4)) # Using the sqrt() function
从 MODULE 导入 TAGNAME 作为 ALIAS