A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-March/110036.html below:

[Python-Dev] Dict access with double-dot (syntactic sugar)

[Python-Dev] Dict access with double-dot (syntactic sugar) [Python-Dev] Dict access with double-dot (syntactic sugar)Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 24 21:38:53 CET 2011
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?

I think the main reason this is a dead end is these
intermediate pythonistas eventually come to realise that,
if you program pythonically, it's actually extremely
rare that you need to index a dictionary with a constant.

Either you have a mostly-fixed set of field names, in
which case you should be using a custom class instead of
a dict, or the set of keys is dynamic, in which case
you're mostly indexing with computed values. Lots of
somedict['foo'] appearing is a code smell.

So there wouldn't be enough use for a somedict..foo syntax
to justify its existence.

-- 
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4