gpt4 book ai didi

python - __init__.py 是干什么用的?

转载 作者:bug小助手 更新时间:2023-10-28 01:27:48 29 4
gpt4 key购买 nike

什么是__init__.py在 Python 源目录中?

最佳答案

它曾经是包的必需部分( old, pre-3.3 "regular package" ,而不是 newer 3.3+ "namespace package" )。

Here's the documentation.

Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory containing an __init__.py file. When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace. The __init__.py file can contain the same Python code that any other module can contain, and Python will add some additional attributes to the module when it is imported.

但是只需点击链接,它包含一个示例,更多信息,以及命名空间包的解释,没有__init__.py的那种包。

关于python - __init__.py 是干什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/448271/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com