/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

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