Module (49%)
Section (85%)

Now we’ll talk about a class decorated with a function that allows us to monitor the fact that some code gets access to the class object attributes. When you’re debugging your code or optimizing it, you might be curious how many times the object attributes are accessed. In such a situation, a class decorator might be handy.

Let's create a simple class representing a car. Each object should own two attributes: mileage and VIN, and it should be possible to read the values of those attributes.



class Car: def __init__(self, VIN): self.mileage = 0 self.VIN = VIN car = Car('ABC123') print('The mileage is', car.mileage) print('The VIN is', car.VIN)