Re: [Python-ideas] [Python-Dev] Dict access with double-dot (syntactic sugar)
I just want to chip in that, as far as syntactic sugar go, `somedict:foo`
looks better than `somedict..foo`.
2c...
~/santa
On Thu, Mar 24, 2011 at 4:40 AM, Jameson Quinn
"class attrdict" is a perennial dead-end for intermediate pythonistas who want to save 3 characters/5 keystrokes for item access. Other languages such as javascript allow "somedict.foo" to mean the same as "somedict['foo']", so why not python? Well, there are a number of reasons why not, beginning with all the magic method names in python.
But saving keystrokes is still a reasonable goal.
So what about a compromise? Allow "somedict..foo", with two dots, to take that place. It still saves 2 characters (often 4 keystrokes; and I find even ', "[", or "]" harder to type than ".").
The "foo" part would of course have to obey attribute/identifier naming rules. So there would be no shortcut for "somedict['$#!%']". But for any identifier-legal foo, the interpreter would just read ..foo as ['foo'].
I would not be surprised if I'm not the first person to suggest this. If so, and there's already well-known reasons why this is a bad idea, I apologize. But if the only reason not to is "we never did it that way before" or "it would be too addictive, and so people would never want to use older python versions" or "headache for tools like pylint", I think we should do it.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/santoso.wijaya%40gmail.com
On 2011-03-24, at 22:03 , Santoso Wijaya wrote:
I just want to chip in that, as far as syntactic sugar go, `somedict:foo` looks better than `somedict..foo`.
2c...
~/santa On the other hand, the colon is generally used for definitions (in Python, with the defined on the left side and the definition on the right one) not for accesses.
On Thu, 2011-03-24 at 14:03 -0700, Santoso Wijaya wrote:
I just want to chip in that, as far as syntactic sugar go, `somedict:foo` looks better than `somedict..foo`.
2c...
~/santa
On Thu, Mar 24, 2011 at 4:40 AM, Jameson Quinn
wrote: "class attrdict" is a perennial dead-end for intermediate pythonistas who want to save 3 characters/5 keystrokes for item access. Other languages such as javascript allow "somedict.foo" to mean the same as "somedict['foo']", so why not python? Well, there are a number of reasons why not, beginning with all the magic method names in python. But saving keystrokes is still a reasonable goal.
So what about a compromise? Allow "somedict..foo", with two dots, to take that place. It still saves 2 characters (often 4 keystrokes; and I find even ', "[", or "]" harder to type than ".").
The "foo" part would of course have to obey attribute/identifier naming rules. So there would be no shortcut for "somedict['$#!%']". But for any identifier-legal foo, the interpreter would just read ..foo as ['foo'].
I would not be surprised if I'm not the first person to suggest this. If so, and there's already well-known reasons why this is a bad idea, I apologize. But if the only reason not to is "we never did it that way before" or "it would be too addictive, and so people would never want to use older python versions" or "headache for tools like pylint", I think we should do it.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/santoso.wijaya%40gmail.com
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
That may be worse. A colon suggests relation, can be confused for dictionary attribution assignment, and can be confused with block declaration.
participants (3)
-
Masklinn
-
Santoso Wijaya
-
Westley Martínez