[Python-ideas] Dict-like object with property access
Ethan Furman
ethan at stoneleaf.us
Tue Jan 31 02:09:51 CET 2012
Nick Coghlan wrote:
> 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.
I agree that making a general purpose object is not feasible, but I am
very glad that Python doesn't put giant roadblocks in the way so we can
make special purpose ones that meet our own needs and tradeoffs.
~Ethan~
More information about the Python-ideas
mailing list