Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 1 | # A more or less complete user-defined wrapper around dictionary objects |
| 2 | |
| 3 | class UserDict: |
| 4 | def __init__(self): self.data = {} |
| 5 | def __repr__(self): return repr(self.data) |
| 6 | def __cmp__(self, dict): |
| 7 | if type(dict) == type(self.data): |
| 8 | return cmp(self.data, dict) |
| 9 | else: |
| 10 | return cmp(self.data, dict.data) |
| 11 | def __len__(self): return len(self.data) |
| 12 | def __getitem__(self, key): return self.data[key] |
| 13 | def __setitem__(self, key, item): self.data[key] = item |
| 14 | def __delitem__(self, key): del self.data[key] |
| 15 | def keys(self): return self.data.keys() |
| 16 | def items(self): return self.data.items() |
| 17 | def values(self): return self.data.values() |
| 18 | def has_key(self, key): return self.data.has_key(key) |