1 | class 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) |
---|