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

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Collection of a bunch of named stuff

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.
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS