I have a question regarding the subclassing behaviour in Python 2.7.
If I subclass from the built-in dict type, it seems that __ dict __ is always empty.
Where does Python save the key/value pairs?
>>> class Foobar(dict):
... pass
...
>>> foobar = Foobar()
>>> foobar.__dict__
{}
>>> foobar['test'] = 1
>>> foobar.__dict__
{}
>>>
A partial answer is that you’re misunderstanding the purpose of
__dict__.__dict__is used to store attributes, not items, and it’s present in most user-defined objects. Indeed, if you subclassdictin the appropriate way,__dict__will have values in it.