dict!ident as equivalent of dict["ident"]

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Mon May 22 04:06:38 EDT 2006


Edward Elliott wrote:
>> With this suggestion,           mapping!identifier
>> becomes fully equivalent to     mapping["identifier"]
> 
> Penny-wise, pound-foolish.  Saves 3 character strokes at the cost of a new
> special-purpose operator which only works in limited circumstances.  To
> avoid parsing ambiguity, identifier can only contain (as the name implies)
> alphanumerics and _.  So your ! is limited not only to dicts but to certain
> keys in certain dicts.  More complicated than it's worth.

Yes, it is limited use-case, but IMHO important one.
The benefits are:
1. Code looks more neat, because IDE will highlight it as identifier,
   and not as string
2. Limited form of code completion (as in PythonWin) becomes possible
3. A bit easier to type, and to read

Anyway, I don't intent strongly on this, I just like to see
common attitude

> So your ! is limited not only to dicts

Not only to dict, but to any class with __getitem__ or __setitem__
methods

-- 
Best regards,
 Alexander                  mailto:alexander.kozlovsky at gmail.com




More information about the Python-list mailing list