Perlish dictionary behavior
Fred Allen
fallen at leveltwo.com
Tue Jun 8 20:53:48 EDT 2004
Mr. Brewer:
I fruitlessly tried your "thing counter", as you can see below.
>>> class AllThingsStartAtZero(dict):
... def getitem (self, key):
... return dict.get(self, key, 0)
...
>>> thingCounts = AllThingsStartAtZero() for thing in
>>> ('a','b','c','d','a'):
... thingCounts[thing] += 1
...
Traceback (most recent call last):
File "<interactive input>", line 2, in ?
KeyError: 'a'
>>> thingCounts
{}
Reason tells me it should work for me using...
PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32.
...as it did for you. The runtime interpreter, however, says
otherwise. Can you see what I've done wrong...I can't?
With thanks in advance, I am,
Respectfully yours,
Fred Allen
More information about the Python-list
mailing list