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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -