python - python中 "import item"中的项目可能是什么?

标签 python import

我有以下层次结构。

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/

相关文章:

python - 如何在 numba 中声明一个值为嵌套列表的类型化字典

javascript - 如何使用套接字 IO 在 Python 客户端和 NodeJS 服务器之间进行通信?

c# - 通过 C# DLL 导入 MapPoint 时遇到问题

仅将 SPSS .sav 文件的特定列读入 R

javascript - 导入默认导出和命名导出是否会加载模块两次?

python - 来自动态导入模块的 ImportError 尝试在同一目录中加载模块

python - 现实生活过程的异步、多线程模拟

Python 在预定时间循环

sql-server - 如何将 Excel 文件导入 SQL Server?

python - 如何不开始相同的任务并等到 celery beat 完成