Implementing fancy indexing in a my class
Some libraries like numpy, pandas or even python lists implement fancy
indexing for its objects. This means I can do things like:
obj[1:3, :]
If I want to offer this functionality in my class I could try to overload
the __get_item__ and the __set_item__ methods:
class myobject(object):
def __get_item__(x):
...
but this doesn't work as I can pass 1:3 as a variable. How can this be
achieved?
No comments:
Post a Comment