[Python-ideas] question - 'bag' type

C. Titus Brown ctb at msu.edu
Thu Apr 15 08:20:59 CEST 2010


On Wed, Apr 14, 2010 at 11:02:54PM -0700, alex23 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)
> 
> [1]: http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named

Well, yes -- but 'sets' weren't exactly rocket science either, and I find
them really useful, too :).

--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the Python-ideas mailing list