Some syntactic sugar proposals
Chris Rebert
clp2 at rebertia.com
Mon Nov 15 01:48:04 EST 2010
On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev <lambdadmitry at gmail.com> wrote:
> Here are some proposals. They are quite useful at my opinion and I'm
> interested for suggestions. It's all about some common patterns.
<snip>
> Second, I saw a lot of questions about using dot notation for a
> "object-like" dictionaries and a lot of solutions like this:
> class dotdict(dict):
> def __getattr__(self, attr):
> return self.get(attr, None)
> __setattr__= dict.__setitem__
> __delattr__= dict.__delitem__
> why there isn't something like this in a standart library?
There is:
http://docs.python.org/library/collections.html#collections.namedtuple
The "bunch" recipe is also fairly well-known; I suppose one could
argue whether it's std-lib-worthy:
http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/
Cheers,
Chris
More information about the Python-list
mailing list