Is __init__ called every time for a subscriptable object that creates a dictionary dynamically?

I have this class, which is, of course, just a working example:

class Intervals(dict):
    def __init__(self, *_):
        self.update({'P5': 7})

class Intervals(metaclass=Intervals):
    pass

I like the idea, because I don’t need an instance that way.

Just, is now, every time when I call Intervals['P5'], __init__ run and a new dictionary built before a value can be returned?


Source: oop

Leave a Reply