I have been assigned an exercise for my python course. The goal is to create some geometric object as subclasses of a Shape object that are going to pass some assertion evaluation.
Here is the code:
class Shape(object):
__metaclass__ = ABCMeta
def __init__(self, coords):
super(Shape, self).__init__()
self._coords = list(map(int, coords))
def __getitem__(self, key):
return self._coords[key]
def move(self, distance):
self._coords = distance
class Point(Shape):
def __init__(self, coords):
super(Point,self).__init__(coords)
if __name__ == '__main__':
p = Point((0,0))
p.move((1,1))
assert p[0,0], p[0,1] == (1,1) # Check the coordinates
The question is how can I access a list of coords that is created in Shape super class with list indices? Is there any possibility for a list to be indexed using another list?