这是我的文件夹结构:
/ Thermal_Formatter
Thermal_Formatter.py
__init__.py
test.py
在Thermal_Formatter.py
中我有这个方法:
def processAndPrint(text):
在 test.py
中这不起作用:
import Thermal_Formatter
Thermal_Formatter.processAndPrint(something)
但这确实:
import Thermal_Formatter.Thermal_Formatter
Thermal_Formatter.Thermal_Formatter.processAndPrint(something)
为什么当我在导入语句和模块调用中写两次模块名称时它会起作用?
最佳答案
因为 Thermal_Formatter
模块位于同名的包内。尝试:
from Thermal_Formatter import Thermal_Formatter
Thermal_Formatter.processAndPrint(something)
如果您想要更明智的方式来使用它。
关于python - 为什么我必须将这个 import 语句写两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21384852/