class attrdict

Alex Martelli aleax at mac.com
Sat Mar 3 21:22:09 EST 2007


MonkeeSage <MonkeeSage at gmail.com> wrote:

> On Mar 3, 7:54 pm, a... at mac.com (Alex Martelli) wrote:
> > Besides missing the warning in the __init__, this also has pretty weird
> > behavior whenever subject to a .pop, .update, .setdefault, del of either
> > item or attr, etc, etc: the attributes and items "get out of sync" (and,
> > catching each and every mutating-method to keep the separate dicts of
> > items and attrs in perfect sync is somewhat of a nightmare).
> 
> Good points. There are many complexities involved, and little actual
> gain. Saving three or four chars isn't worth all the trouble. I hadn't
> fully thought-out the situation.

You make a good point.  I do like being able to say foo.bar=baz rather
than foo['bar']=baz in certain cases -- not so much to save 3 chars, but
to avoid excessive punctuation; however, I don't really need this AND
all of dict's power at the same time, so, I don't inherit from dict:-).


Alex



More information about the Python-list mailing list