8.4 Managing global and singleton objects
The Python environment contains a number of implicit global objects. These objects provide a convenient way to work with a collection of other objects. Because the collection is implicit, we’re saved from the annoyance of explicit initialization code.
One example of this is an implicit random number generating object in the random module. When we evaluate random.random(), we’re actually making use of an instance of the random.Random class.
Because a module is only imported once, a module implements the Singleton design pattern. We can rely on this technique to implement these global singletons.
Other examples of this include the following:
The collection of data encoders and decoders (codecs) available. The codecs module has a registry for encoders and decoders. We can add encodings and decodings to this registry.
The webbrowser module has a registry of known browsers.
...