This article mainly introduces _ init _ in the Python module package __. py file function, simple analysis of _ init __. the role of py in the process of transferring modules and packages. if you need it, refer to the example in this article to describe _ init _ in the Python module package __. py file function. We will share this with you for your reference. The details are as follows:
It has been more than a year since django was used for development __. the significance of the existence of the py file. it is too important to see the introduction to it.
Module Package:
A package is usually a directory. The first file under the Directory is _ init _. py. Then there are some module files and subdirectories. if there are also _ init _. py in the subdirectory, it is the sub-package of this package.
Like this:
Package1/_ init _. py Module1.py Module2.py Package2
Package1/Package2/_ init _. py Module1.py Module2.py
We can import a package as follows:
import Package1
You can also call a sub-module and sub-package:
from Package1 import Module1 from Package1 import Package2 ,import Packag1.Module1 ,import Packag1.Package2
You can go deep into several layers of package structure:
from Package1.Package2 import Module1 ,import Package1.Package2.Module1
In general, I think the essence of the package should be in the _ init _. py file.