I am trying to overload the [] operator for a list to work like a circular list.
class circularList(list):
def __init__(self, *args):
list.__init__(self,args)
def __getitem__(self, key):
return list.__getitem__(self, key%self.length)
def __setitem__(self, key, value):
return list.__setitem__(self, key%self.length, value)
When running this code in the sage terminal, I get the following error:
TypeError: Error when calling the metaclass bases
list() takes at most 1 argument (3 given)
sage: def __getitem__(self, key):
....: return list.__getitem__(self, key%self.length)
....:
sage: def __setitem__(self, key, value):
....: return list.__setitem__(self, key%self.length, value)
This would be used as follows:
circle = circularlist([1,2,3,4])
Does anyone happen to know what I am doing wrong?