oop - How come this python class prints out my kwargs? -



oop - How come this python class prints out my kwargs? -

class meta(dict): def __init__(self, indexed, method, *args, **kwargs): super(meta, self).__init__(*args, **kwargs) print self

how come prints kwargs?

m = meta(indexed='hello', method='distance', a='3', b='4')

when run this, prints out dictionary kwargs, when i'm expecting empty dictionary...

that's because dict class initializes contents keyword arguments passed constructor:

>>> dict(indexed='hello', method='distance', a='3', b='4') {'a': '3', 'indexed': 'hello', 'b': '4', 'method': 'distance'}

since class calls dict's constructor keyword arguments passed own constructor, dictionary indeed initialized , same behavior observed.

python oop

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -