In chapters two through nine of this book, we looked at a number of techniques for designing classes, which are the foundation of object-oriented design and programming. The module is a collection of classes; it is a higher-level grouping of related classes and functions. It's rare to try to reuse a single class in isolation.
Consequently, the module is a fundamental component of Python implementation and reuse. A properly designed module can be reused because the needed classes and functions are bundled together. All Python programming is provided at the module level.
A Python module is a file. The filename extension must be .py. The filename in front of .py must be a valid Python name. Section 2.3 of Python Language Reference provides us with the complete definition of a name. One of the clauses in this definition is as follows:
Operating system (OS) filenames permit more characters from the ASCII range than Python names; this extra OS complexity must be avoided. In particular, hyphens are a potential problem in Python module names; use underscores instead in complex file names. Because the stem of the filename (without the .py extension) becomes the module name, these names should also be valid Python identifiers.
Every time we create a .py file, we create a module. Often, we'll create Python files without doing much design work. This simplicity is a benefit of using Python. In this chapter, we'll take a look at some of the design considerations to create a reusable module.
Now let's take a look at some of the design patterns for Python modules.