How to do it...

  1. Define the class with a descriptive name:

        class CounterStatistics: 
  1. Write the __init__ method to include the object to which this object will be connected:

        def __init__(self, raw_counter:Counter): 
            self.raw_counter = raw_counter
 

We've defined a method function that takes a Counter object as an argument value. This Counter object is saved as part of the Counter_Statistics instance.

  1. Initialize any other local variables that might be useful. Since we're going to calculate values eagerly, the most eager possible time is when the object is created. We'll write references to some yet to be defined functions:

        self.mean = self.compute_mean() 
        self.stddev = self.compute_stddev() 

We've eagerly computed the mean and standard ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.