Creating a package
A package is a directory that contains module files plus one additional file. Each package must have an __init__.py file. This file must be present and is often empty.
The poem, Zen of Python, by Tim Peters, offers the following advice:
Flat is better than nested.
The idea is to organize Python applications into a flat collection of modules to the greatest extent possible. A deeply-nested, complex hierarchy of packages isn't considered helpful.
We can use a package in two ways. We can import a module that's part of a package. The standard library, for example, has an XML package with several XML parser modules. We can use import xml.etree to import the etree module from the XML package. In this case, the __init__.py file has a comment ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access