[Python-ideas] Dict-like object with property access
Mike Meyer
mwm at mired.org
Thu Jan 26 18:38:15 CET 2012
On Thu, 26 Jan 2012 19:25:40 +0200
anatoly techtonik <techtonik at gmail.com> wrote:
> I expected to find the answer to this question in FAQ, but because
> there is no FAQ I ask it anyway.
Better to have searched the python-ideas mail list archive.
> 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.
Because it doesn't work in general. There are strings that can be used
as an index, but not as an attribute. There are existing attributes
that you have to avoid, etc.
The only way this really works in practice is if you start with a
fixed set of names you want to access, in which case
collections.namedtuple will probably do the job.
<mike
More information about the Python-ideas
mailing list