Perlish dictionary behavior

Robert Brewer fumanchu at amor.org
Tue Jun 8 22:33:44 EDT 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
line.


FuManChu




More information about the Python-list mailing list