[Python-ideas] Dict-like object with property access

anatoly techtonik techtonik at gmail.com
Thu Jan 26 18:25:40 CET 2012


I expected to find the answer to this question in FAQ, but because there is
no FAQ I ask it anyway.

How about adding a new standard dict-like container type that allows access
using . (dot) to its members instead of ['index']?
Why? It is convenient to write options.help instead of options['halp'] etc.

Example:
>>> mydict = container(someprop=somevalue)
>>> mydict['someprop']
somevalue
>>> mydict.someprop
somevalue
>>> mydict.otherprop
Exception KeyError ...

I know that it is easy to implement, but wouldn't it be nice to make it
available by default?
A side benefit of having this in stdlib is that newbies will be aware of
the behaviour of derived classes without having to understand the mechanics
of magic methods.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120126/d99d3ae1/attachment.html>


More information about the Python-ideas mailing list