Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The __init__.py file serves to declare and initialize a module package; Python automatically runs its code the first time you import through a directory in a process. Its assigned variables become the attributes of the module object created in memory to correspond to that directory. It is also not optional—you can’t import through a directory with package syntax unless it contains this file.
Use the from statement
with a package to copy names out of the package directly, or use
the as extension with the
import statement to rename the
path to a shorter synonym. In both cases, the path is listed in
only one place, in the from or
import statement.