Hacker News new | ask | show | jobs
by klyrs 975 days ago
> Don't you think `x["foo"] == 5` but `x.foo == 4` is a hell of a lot confusing ?

No. They're different notations; one means `x.__getitem__('foo')` and the other means `x.__getattribute__('foo')`. Why should they be the same? It isn't confusing that `5-4 == 1` but `5+4 == 9`, after all.

If we assume that the dict class was enhanced with your proposed equivalence, would you want `d['items']` to be the function `d.items`? Would that not make 'items' a forbidden key?