python - ".main"在python源代码中是什么意思?

标签 python

在python的源代码中:usr/local/lib/python3.3/unittest/__init__.py

from .result import TestResult
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
                   skipUnless, expectedFailure)
from .suite import BaseTestSuite, TestSuite
from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
                     findTestCases)
from .main import TestProgram, main
from .runner import TextTestRunner, TextTestResult
from .signals import installHandler, registerResult, removeResult, removeHandler

我无法理解 .result.main。为什么它们的名称中有一个点前缀?

最佳答案

它叫做 relative import .

这意味着您从与此代码所在的模块相同的目录中的模块导入。如果没有点,它将从 PYTHON PATH 中找到的第一个模块导入。

关于python - ".main"在python源代码中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19785485/

相关文章:

php - 如何将 sklearn 代码嵌入到我的 PHP 后端代码中?

python - 使用 pytest 参数化类测试

python - 内存错误 : numpy. genfromtxt()

python - 如何使用 python subprocess 命令在不同目录中运行 shell 命令?

Python、Sqlite3 - 如何将列表转换为 BLOB 单元格

python - pytorch:计算向量函数的向量雅可比积

python - 导入 Eve,但运行 run.py 时,显示没有名为 eve 的模块

python - Tensorflow 提取索引不等于零

python - 如何配置 setup.py 为测试步骤运行 tox?

python - 在 Python 中更改键盘锁