Home >Backend Development >Python Tutorial >The role of __init__.py in python

The role of __init__.py in python

silencement
silencementOriginal
2019-05-24 17:49:559285browse

The role of __init__.py in python

init.pyThe function of the file is to turn the folder into a Python module. Each module in Python has __init__.py in its package. document.

Usually the __init__.py file is empty, but we can also add other functions to it. When we import a package, we actually import its __init__.py file. In this way, we can batch import the modules we need in the __init__.py file, instead of importing them one by one.

The role of __init__.py in python

There is also an important variable in init.py, all, which is used to import all modules

The role of __init__.py in python

The objects that can be imported by the import statement are of the following types

The role of __init__.py in python

##When importing a module, the interpreter looks for imported files in the order of the directories in the sys.path list

The role of __init__.py in python

The above is the detailed content of The role of __init__.py in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn