I have this initialiser for a line class in Python and it takes two points as a parameter. The problem is my initialiser is only copying the references. So self.point0 and point 0 are pointing to the same object. I am not really sure how to change that so that I am not just copying the reference. Line class:
def __init__(self, point0, point1):
self.point0 = point0
self.point1 = point1
Point class:
def __init__(self, x, y):
self.x = x
self.y = y
copy.copy
not satisfactory?Line
andPoint
could easily be redefined asnamedtuple
s. They'd be immutable, and perhaps would enforce the exclusivity you would prefer.copy.copy
would still work, as would creating new instances.