[Python-ideas] question - 'bag' type

Michael Foord fuzzyman at gmail.com
Thu Apr 15 13:43:07 CEST 2010


On 15 April 2010 08:02, alex23 <wuwei23 at gmail.com> wrote:

> On Apr 15, 3:02 pm, "C. Titus Brown" <c... at msu.edu> wrote:
> >    b = bag(foo=bar, baz=bif)
> >
> >    assert b.foo == bar
> >    assert b.bz == bif
>
> I've always known this as a 'bunch' after Alex Martelli's recipe[1].
> It's handy, but at 3 lines of code not an urgent candidate (IMO) for
> stdlib:
>
>  class Bunch:
>    def __init__(self, **kwds):
>      self.__dict__.update(kwds)
>


Yeah, we've used this class a tonne - especially for testing where you just
need a quick object with a bunch of attributes. I think we added a repr as
well. It would certainly be a nice harmless addition to the collections
module.

Michael



>
> [1]:
> http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
http://www.ironpythoninaction.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100415/1c9d2c5e/attachment.html>


More information about the Python-ideas mailing list