[Python-ideas] question - 'bag' type

M.-A. Lemburg mal at egenix.com
Thu Apr 15 09:31:32 CEST 2010


C. Titus Brown wrote:
> Hi all,
> 
> this seems like the right forum to ask -- is there a reason why Python
> doesn't have a 'bag' builtin type, e.g.
> 
>    b = bag(foo=bar, baz=bif)
> 
>    assert b.foo == bar
>    assert b.bz == bif
> 
> ?

That's what's normally called a "namespace" in Python-land
and can easily be had via a regular instance:

class Namespace:
    def __init__(self, **kws):
        self.__dict__.update(kws)

b = Namespace(foo=bar, baz=bif)

assert b.foo == bar
assert b.bz == bif

For a more elaborate example of a namespace class, see mx.Misc.Namespace
from our eGenix mx Base package:

    http://www.egenix.com/products/python/mxBase/

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 15 2010)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/



More information about the Python-ideas mailing list