Perlish dictionary behavior

F

Fred Allen

Mr. Brewer:

I fruitlessly tried your "thing counter", as you can see below.
.... def getitem (self, key):
.... return dict.get(self, key, 0)
.... .... thingCounts[thing] += 1
....
Traceback (most recent call last):
{}

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
 
C

Chris Liechti

(e-mail address removed) (Fred Allen) wrote in
Mr. Brewer:

I fruitlessly tried your "thing counter", as you can see below.

... def getitem (self, key):

it's __getitem__ note the underlines.
... return dict.get(self, key, 0)
... ... thingCounts[thing] += 1
...
Traceback (most recent call last):
{}

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top