Setdefault bypasses __setitem__

Ron Garret rNOSPAMon at flownet.com
Thu Oct 13 02:24:36 EDT 2005


Is this a bug or a feature?

class mydict(dict):
   def __setitem__(self, key, val):
     print 'foo'
     dict.__setitem__(self, key, val)

>>> d=mydict()
>>> d[1]=2
foo
>>> d.setdefault(2,3)
3

rg



More information about the Python-list mailing list