我有以下层次结构。
A\
B\
__init__.py
testB.py
C\
__init__.py
test1.py
test2.py
当我在 testB.py 中编写以下内容时
import C
test1.func1()
test2.func2()
为什么我无法调用 test1.py 或 test2.py 中定义的函数?
注意:在 test1.py 和 test2.py 中分别定义了一个名为 func1 和 func2 的函数。
最佳答案
您可能会以 C 方式考虑 Python 导入。但 Python 导入的工作方式如下:
import C.test1
import C.test2
C.test1.func1()
C.test2.func2()
或
from C import test1, test2
test1.func1()
test2.func2()
关于python - python中 "import item"中的项目可能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37496828/