John Posner wrote:
On 7/31/2010 1:31 PM, John Posner wrote:
Caveat -- there's another description of defaultdict here:
http://docs.python.org/library/collections.html#collections.defaultdict
... and it's bogus. This other description claims that __missing__ is a
method of defaultdict, not of dict.
__missing__ isn't a method of dict:
--> print dir(dict())
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__',
'__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__',
'__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy',
'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys',
'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update',
'values']
I will agree that the current defaultdict description does not make it
clear that __missing__ can be defined for *any* subclass of dict,
although the dict description does go over this... is that the confusion
you are talking about? If not, could you explain?
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list