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

Nick Coghlan ncoghlan at gmail.com
Tue Jan 31 01:49:33 CET 2012

On Tue, Jan 31, 2012 at 10:28 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Nick Coghlan wrote:
>> *Outside* the standard library, it's "practicality beats purity" that
>> wins. People *like* being able to type ".attr" instead of "['attr']"
>> when a field name happens to be a legal identifier.
> Yes, but people like all sorts of things that aren't good for them, and
> while Python can and does allow people to shoot themselves in the foot, I
> don't think we should be providing a standard foot-shooting class :)

You don't have to persuade *me* of that. I spent a bunch of time years
ago working with Steven Bethard on the "namespaces" proto-PEP and
package, and the idea is logically incoherent enough that it's simply
hard to cover all the use case variants in a single class. You either
end up with a baroque monstrosity that handles everything, or you have
people still rolling their own because the "official" one doesn't
behave exactly the way they want.

About the only variant of the idea that I *could* get behind these
days is a collections.record class factory that was basically a
variant of collections.namedtuple that produced mutable objects
instead of tuples.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list