I'm using the excellent 'auto_dict'
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/537637) but I'd like
to be able to extend it.
Currently my program has
class auto_dict(dict):
def __getitem__(self, key):
return self.setdefault(key, self.__class__())
daily=auto_dict()
try:
daily['today']['now'].append((1,2))
except AttributeError:
daily['today']['now']=[(1,2)]
Which works OK but I thought it would be easy to supply an 'append' method to
the auto_dict class that would save me from having all those try/except blocks
scattered through my code ie I could just say
daily['today']['now'].append((1,2))
and the class would take care of catching the exception and assigning the list.
I tried adding
def append(self,item):
self=[item]
return self
to the class definition but it doesnt actually assign the value.
Can it be done this way? Some other way? Or am I stuck using the try/except
blocks?
(please CC me since I'm not subscribed to the list)
Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/mail
--
http://mail.python.org/mailman/listinfo/python-list