Perlish dictionary behavior
Fred Allen
fallen at leveltwo.com
Wed Jun 9 12:48:36 EDT 2004
Dear Mr. Brewer:
Thank you for your rapid and eminently helpful reply. I remain,
Gratefully,
Fred Allen
-----Original Message-----
From: Robert Brewer [mailto:fumanchu at amor.org]
Sent: Tuesday, June 08, 2004 7:34 PM
To: Fred Allen; python-list at python.org
Subject: RE: Perlish dictionary behavior
Fred Allen wrote:
> I fruitlessly tried your "thing counter", as you can see below.
>
> >>> class AllThingsStartAtZero(dict):
> ... def getitem (self, key):
> ... return dict.get(self, key, 0)
> ...
As Chris pointed out, it should be __getitem__ (two leading underscores
and two trailing). If you read the original on Google (say, from the
link in Dr. Dobb's? ;), they cut out underscores somewhere along the
line.
FuManChu
More information about the Python-list
mailing list