Any directory with an file is considered a Python package.The different modules in the package are imported in a similar manner as plainmodules, but with a special behavior for the init.py
file, which isused to gather all package-wide definitions.
A commonly seen issue is to add too much code to init.py
files. When the project complexity grows, there may be sub-packages andsub-sub-packages in a deep directory structure. In this case, importing asingle item from a sub-sub-package will require executing allinit.py
files met while traversing the tree.
Lastly, a convenient syntax is available for importing deeply nested packages:. This allows you to use mod in place of theverbose repetition of very.deep.module
.