It used to be a required part of a package ( old, pre-3.3 "regular package" , not newer 3.3+ "namespace package" ).
(它曾经是软件包的必需部分( 旧的3.3之前的“常规软件包” ,而不是新的3.3+“命名空间软件包” )。)
Here's the documentation.
(这是文档。)
Python defines two types of packages, regular packages and namespace packages.
(Python定义了两种类型的程序包,常规程序包和名称空间程序包。)
Regular packages are traditional packages as they existed in Python 3.2 and earlier. (常规软件包是Python 3.2及更早版本中存在的传统软件包。)
A regular package is typically implemented as a directory containing an __init__.py
file. (常规软件包通常实现为包含__init__.py
文件的目录。)
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. (导入常规程序包时,将隐式执行此__init__.py
文件,并将其定义的对象绑定到程序包名称空间中的名称。)
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代码,并且在导入时Python将向该模块添加一些其他属性。)
But just click the link, it contains an example, more information, and an explanation of namespace packages, the kind of packages without __init__.py
.
(但是只需单击链接,它包含一个示例,更多信息以及名称空间包的说明,即不带__init__.py
的包的类型。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…