Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Collection of a bunch of named stuff (See related posts)

Taken from this recipe and its comments.
class bunch(dict):
    def __init__(self,**kw):
        dict.__init__(self,kw)
        self.__dict__.update(kw)

Usage is simple.
>>> o = bunch(a='A', b='B')
>>> o
{'a': 'A', 'b': 'B'}
>>> o.a
'A'
>>> o.b
'B'
>>> 

You can use it as both an object and dict.

You need to create an account or log in to post comments to this site.


Click here to browse all 4860 code snippets

Related Posts