This example describes the __init__.py file feature in the Python module package. Share to everyone for your reference, as follows:
It has been more than a year since the development of Django, but there is little attention to the meaning of the existence of the __init__.py file in the Python module, and the introduction of it is a big surprise.
Module Package:
A package is usually always a directory, and a file headed by the directory is __init__.py. Then there are some module files and subdirectories, if there are __init__.py in the subdirectory then it is the child package of this package.
It's almost like this:
package1/__init__.py module1.py module2.py Package2
package1/package2/__init__.py module1.py module2.py
We can import a package like this:
Or, a sub-module and a sub-package are transferred:
From Package1 import Module1 from Package1 import Package2 , import packag1.module1
You can drill down into several layers of package structure:
From Package1.package2 import Module1
In general, I think, the essence of the package should be in the __init__.py this file.
More interested in Python related content readers can view this site topic: "Python Picture Operation skills Summary", "Python data structure and algorithm tutorial", "Python Socket Programming Skills Summary", "Python function Use Tips", " Python string manipulation Tips Summary, Python Introductory and Advanced classic tutorials, and Python file and directory operations tips
I hope this article is helpful for Python program design.