在 Python 中从 `foo.py` 导入和从 `foo/__init__.py` 导入有什么区别
What is the difference between importing from `foo.py` and importing from `foo/__init__.py` in Python
如果foo.py
和foo/__init__.py
相同且不包含相对导入。如果您使用以下内容导入:
from foo import X # (or import foo)
我认为没有区别。当文件变得太大并且我想将它分成一个包和多个文件时,我做了很多次。但事实并非如此 this commit failing the tests for pylint.
pylint/utils.py → pylint/utils/__init__.py
File renamed without changes.
它使 3 个功能测试失败(logging_format_interpolation
、deprecated_methods_py3
和 redundant_unittest_assert
)。这是真正的变基之后的变基,每次来自 master 分支的提交都工作正常。我在启动 tox 时也使用 --recreate
选项。
包含这些检查器的 stdlib.py 文件似乎甚至没有从 pylint.utils
导入某些东西(它使用 pylint.checker.utils
),所以我不知道为什么它会崩溃,但确实如此。
此文件包含一些以下划线 (_function_name
) 开头的函数,这可能是问题所在吗?
真的没有区别。 pylint 主分支很长时间没有通过测试套件,请参阅 this comment。
如果foo.py
和foo/__init__.py
相同且不包含相对导入。如果您使用以下内容导入:
from foo import X # (or import foo)
我认为没有区别。当文件变得太大并且我想将它分成一个包和多个文件时,我做了很多次。但事实并非如此 this commit failing the tests for pylint.
pylint/utils.py → pylint/utils/__init__.py
File renamed without changes.
它使 3 个功能测试失败(logging_format_interpolation
、deprecated_methods_py3
和 redundant_unittest_assert
)。这是真正的变基之后的变基,每次来自 master 分支的提交都工作正常。我在启动 tox 时也使用 --recreate
选项。
包含这些检查器的 stdlib.py 文件似乎甚至没有从 pylint.utils
导入某些东西(它使用 pylint.checker.utils
),所以我不知道为什么它会崩溃,但确实如此。
此文件包含一些以下划线 (_function_name
) 开头的函数,这可能是问题所在吗?
真的没有区别。 pylint 主分支很长时间没有通过测试套件,请参阅 this comment。