PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/galaxy/util/bunch.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 30 lines | 12 code | 0 blank | 18 comment | 2 complexity | d426795f7dc1396f26e3502de59142f8 MD5 | raw file
 1class Bunch( object ):
 2    """
 3    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308
 4
 5    Often we want to just collect a bunch of stuff together, naming each item of
 6    the bunch; a dictionary's OK for that, but a small do-nothing class is even handier, and prettier to use.
 7    """
 8    def __init__(self, **kwds):
 9        self.__dict__.update(kwds)
10
11    def get(self, key, default=None):
12        return self.__dict__.get(key, default)
13
14    def __iter__(self):
15        return iter(self.__dict__)
16
17    def items(self):
18        return self.__dict__.items()
19
20    def __str__(self):
21        return '%s' % self.__dict__
22
23    def __nonzero__(self):
24        return bool(self.__dict__)
25
26    def __setitem__(self, k, v):
27        self.__dict__.__setitem__(k, v)
28
29    def __contains__(self, item):
30        return item in self.__dict__