class Meta(dict):
def __init__(self, indexed, method, *args, **kwargs):
super(Meta, self).__init__(*args, **kwargs)
print self
How come this prints my kwargs?
m = Meta(indexed='hello', method='distance', a='3', b='4')
When I run this, it prints out a dictionary with my kwargs, when I’m expecting an empty dictionary…
That’s because the
dictclass initializes its contents from the keyword arguments passed to its constructor:Since your class calls
dict‘s constructor with the keyword arguments passed to its own constructor, the dictionary is indeed initialized and the same behavior is observed.