There are three commonly seen design patterns for Python modules:
- Importable library modules: These are meant to be imported. They contain definitions of classes, functions, and perhaps some assignment statements to create a few global variables. They do not do any real work; they can be imported without any worry about the side effects of the import operation. There are two use cases that we'll look at:
- Whole module: Some modules are designed to be imported as a whole, creating a module namespace that contains all of the items.
- Item collection: Some modules are designed to allow individual items to be imported, instead of creating a module object; the math module is a prime example of this design.
- Runnable ...