mixins.py 492 B

1234567891011121314151617181920
  1. # Copyright (c) 2011, Manfred Moitzi
  2. # License: MIT License
  3. class SubscriptAttributes:
  4. def __getitem__(self, item):
  5. if hasattr(self, item):
  6. return getattr(self, item)
  7. else:
  8. raise KeyError(item)
  9. def __setitem__(self, key, value):
  10. if hasattr(self, key):
  11. setattr(self, key, value)
  12. else:
  13. raise KeyError(key)
  14. def __contains__(self, item):
  15. return hasattr(self, item)