为什么我要写两次导入语句?

2024-10-01 07:17:09 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我的文件夹结构:

/ 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语句和模块调用中写了两次模块名就可以了?你知道吗


Tags: 模块方法textpytestimport文件夹init
1条回答
网友
1楼 · 发布于 2024-10-01 07:17:09

因为Thermal_Formatter模块位于同名的包中。尝试:

from Thermal_Formatter import Thermal_Formatter
Thermal_Formatter.processAndPrint(something)

如果你想用更理智的方法来使用它。你知道吗

相关问题 更多 >