简体   繁体   English

__init__.py文件是模块吗?

[英]Is the __init__.py file a module?

Is __init__.py file is a module ? __init__.py文件是模块吗? I am learning python and come across packages and modules and i have one doubt that weather __init__.py file can be consider as module Since every python file is module so can we consider __init__.py as module ? 我正在学习python并遇到软件包和模块,并且我怀疑天气__init__.py文件可以视为模块。由于每个python文件都是模块,因此我们可以将__init__.py视为模块吗?

According to the official glossary a module is 根据官方词汇表,一个模块是

An object that serves as an organizational unit of Python code. 用作Python代码的组织单位的对象。 Modules have a namespace containing arbitrary Python objects. 模块具有一个包含任意Python对象的名称空间。 Modules are loaded into Python by the process of importing. 通过导入过程将模块加载到Python中。

Which (imho) borders on gibberish for saying " module objects or files with Python code." 哪个(imho)会说“带有Python代码的module对象或文件”,这在胡言乱语的旁边。

Since even an empty __init__.py file contains valid Python code, and you can import it via import __init__ , it would technically be considered a module. 由于即使一个空的__init__.py文件也包含有效的Python代码,并且您可以通过import __init__导入它,因此从技术上讲,它被视为一个模块。 I don't know how this knowledge could be useful. 我不知道这些知识如何有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM