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):

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.