Perlish dictionary behavior

Robert Brewer fumanchu at
Wed Jun 9 04:33:44 CEST 2004

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