How do I represent this object unambiguously?
There are 2 ways. First is to change
def __repr__(self):
return "MyLine({}, {}, {}, {})".format(self.start_point.x, self.start_point.y, self.end_point.x, self.end_point.y)
2nd, is to use attribute getters and setters.
class MyLine:
def __init__(self,start_x=0, start_y=0, end_x=0, end_y=0):
self.start_x, self.start_y, self.end_x, self.end_y = start_x, start_y, end_x, end_y
start_point = MyPoint(start_x, start_y)
self._start_point = start_point
end_point = MyPoint(end_x, end_y)
self._end_point = end_point
def __str__(self):
return "{} to {}".format(self._start_point, self._end_point)
@property
def start_point(self):
return self._start_point
@start_point.setter
def start_point(self, point):
self._start_point = point
self.start_x = point.x
self.start_y = point.y
@property
def end_point(self):
return self._end_point
@end_point.setter
def end_point(self, point):
self._end_point = point
self.end_x = point.x
self.end_y = point.y
def __repr__(self):
return "MyLine({}, {}, {}, {})".format(self.start_x, self.start_y, self.end_x, self.end_y)