Transfer from http://www.cnblogs.com/BeginMan/p/3183629.html
Python has a __init__.py file in each of the module's packages, and with this file we can import the module in this directory.
So, what other functions does __init__.py have?
In fact, __init__.py inside can still have content, we import a package, actually imported its __init__.py file.
We can then import other packages, or modules, into the __init__.py file.
[Python]
Import Readers
Import writers
Import commands
Import Users
Import Meta
Import Auth
Import Admin
This way, when we import this package, the __init__.py file runs automatically. To help us import so many modules, we do not need to write all the import statements in a file, but also reduce the amount of code.
There is no need to import the module.
There is also an important variable in __init__.py, called __all__. We sometimes take a trick of "import All", which is this:
From PackageName Import *
Import then imports the sub-modules and sub-packages that are registered in the __ALL__ list in the package __init__.py file into the current scope. Like what:
#文件 __init__.py
__all__ = ["Module1", "Module2", "SubPackage1", "SubPackage2"]
such as: In a bag with foo.py, __init__.py
#__init__.pyimport osimport datetime
#foo.pyimport *print Datetime.datetime.now ()
Then output: 2013-07-11 11:34:41.250000
< turn >python: __init__.py usage