Welcome to the bright side; -)
Sounds like you mean __getitem__(self, key). and __setitem__(self, key, value).
Try:
class my_class(object):
def __getitem__(self, key):
return some_value_based_upon(key)
def __setitem__(self, key, value):
return store_based_upon(key, value)
i = my_class()
i[69] = 'foo'
print i[69]
Update (following comments):
If you want to use tuples as your key, you can use dictone that has all this functionality, namely:
>>> a = {}
>>> n = 0, 1, 2
>>> a[n] = 'foo'
>>> print a[n]
foo
source
share