Why is there no natural syntax for accessing attributes with names not being valid identifiers?
roy at panix.com
Wed Dec 4 14:23:24 CET 2013
In article <17gt99hg615jfm7bdid26185884d2pfdkf at 4ax.com>,
Tim Roberts <timr at probo.com> wrote:
> Piotr Dobrogost <p at google-groups-2013.dobrogost.net> wrote:
> >Attribute access syntax being very concise is very often preferred
> >to dict's interface.
> It is not "very concise". It is slightly more concise.
> x = obj.value1
> x = dct['value1']
> You have saved 3 keystrokes. That is not a significant enough savings to
> create new syntax. Remember the Python philosophy that there ought to be
> one way to do it.
I'll trade typing [ ' ' ] for . any day. Easier to type, easier to
read. It's not just the character count, it's that you need to move
your fingers off the home row (or, at the very least, a big stretch with
your pinkie) to reach the brackets. I suppose that depends on your
particular keyboard layout and typing style/skill.
More information about the Python-list