3 Suggestions to Make Python Easier For Children
Skip Montanaro
skip at pobox.com
Tue Aug 5 08:31:05 EDT 2014
On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>
> I wonder if that should be built into dict.
Short answer, no. I'm sure it's been proposed before. Attributes ≠
keys. When you see something.somethingelse anywhere else in Python,
"somethingelse" is an attribute reference. When you see
something[somethingelse], "somethingelse" is an index value or
key. Why destroy that symmetry in dictionaries?
JavaScript objects have that feature. I find it mildly confusing
because whenever I see it I have to pause to consider whether the name
I am looking at is an attribute or a key. This little JS code I just
typed at my console prompt was also mildly surprising:
> var x = {};
undefined
> x.valueOf(47)
Object {}
> x["valueOf"] = 12
12
> x.valueOf
12
> x.valueOf(47)
TypeError: number is not a function
Still, in my own JS code I tend to lapse into that usage, probably
because so much other code out in the wild uses dot notation for key
references. (Doesn't make it right, just makes me lazy.)
Skip
More information about the Python-list
mailing list