【发布时间】:2014-01-27 15:31:56
【问题描述】:
这是我的文件夹结构:
/ 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)
为什么我在 import 语句和模块调用中两次写入模块名称时它会起作用?
【问题讨论】:
-
因为两次都不是模块名;你有一个包和一个同名的模块。
-
写
from Thermal_Formatter import Thermal_Formatter(Wooble 说得对。) -
Importing packages in Python 的可能重复项