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 an explicit initialization code.
One example of this is an implicit random number generating object that's part of the random
module. When we evaluate random.random()
, we're actually making use of an instance of the random.Random
class that's an implicit part of the random
module.
Other examples of this include the following:
- The collection of numeric types available. By default, we only have
int
,float
, andcomplex
. We can, however, add more numeric types, and they will work seamlessly with existing types. There's a global registry of available numeric types. - The collection of data code/decode methods (codecs) available. The
codecs
module lists the available encoders and decoders. This also involves an implicit registry. We can add encodings...