为什么我在添加模块时没有属性错误"as"



我有一个目录module,我有一个python文件tools.py

我需要从module的父目录中导入tools.py

当我指定import module.tools时,一切正常。

但是import module.tools as tools不起作用。我得到一个错误:Module module has no attribute tools

不使用

as ,使用 from module import tools 。这将仅从 module 导入tools

from module import tools

如果要将工具重命名为更短的名称,可以稍后在代码中执行此操作。

t = tools

最新更新