This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [1]: import index | |
| In [2]: i = index.Multidex(unique_keys=('pk',), common_keys=('name',)) | |
| In [3]: class Person(object): | |
| def __init__(self, name): | |
| global last_pk | |
| self.pk = last_pk | |
| last_pk += 1 | |
| self.name = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SliceDict(dict): | |
| def __getitem__(self, item): | |
| if isinstance(item, slice): | |
| return self.get(item.start, item.stop) | |
| return super(SliceDict, self).__getitem__(item) | |
| >> d = SliceDict() | |
| >> d['a'] = 1 | |
| >> d['a'] | |
| 1 |