[Python-ideas] Fwd: Dict access with double-dot (syntactic sugar)

M.-A. Lemburg mal at egenix.com
Thu Mar 24 14:44:25 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']",
> they think, so why not python? Well, there are a number of reasons why not,
> beginning with the possible conflicts with keywords or any of the magic
> method names in python.

You can have all that in Python as well - you only need to create
a dictionary type that maps attribute access to dictionary access.

Wrapping existing dictionaries like that is also easily possible.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Mar 24 2011)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-ideas mailing list