Each module package in python contains a _ init _. py file. With this file, we can import the module under this directory.
So, __init _. py, what other functions are there?
Actually, __init _. py still contains content. When we import a package, we actually import its _ init _. py file.
We can import other packages or modules in the _ init _. py file.
[Python]
Import readers
Import writers
Import commands
Import users
Import meta
Import auth
Import admin
In this way, when we import this package, the __init _. py file runs automatically. After importing so many modules, we do not need to write all the import statements in one file, which can reduce the amount of code.
You do not need to import modules one by one.
Another important variable in _ init _. py is called _ all __. We sometimes make a trick to "import all", that is:
From PackageName import *
In this case, import the sub-modules and sub-packages registered in the _ init _. py file _ all _ list to the current scope. For example:
# File _ init _. py
_ All _ = ["Module1", "Module2", "subPackage1", "subPackage2"]
Author: Chen jianhong