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.
There is also an important variable in init.py, all, which is used to import all modules
The objects that can be imported by the import statement are of the following types
##When importing a module, the interpreter looks for imported files in the order of the directories in the sys.path list
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!