Perlish dictionary behavior

Fred Allen fallen at
Wed Jun 9 18:48:36 CEST 2004

Dear Mr. Brewer: 

Thank you for your rapid and eminently helpful reply. I remain,


Fred Allen

-----Original Message-----
From: Robert Brewer [mailto:fumanchu at] 
Sent: Tuesday, June 08, 2004 7:34 PM
To: Fred Allen; python-list at
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


More information about the Python-list mailing list