I have defined a class called Point which defines a point in the x, y coordinate system. The definition and methods are shown below. I created my own version of the str method to return the created point in a printable form (required). However, when I try to pass the returned point to another method to determine the distance between two points (p1 and p2), using the call p.DistanceTo(p2), I get the following error from the attempt to parse the string (p2) passed into the method:
AttributeError: Point instance has no attribute 'find'
When I pass in a string defined as p2 should be it works just fine. Any help would be greatly appreciated. Thank you.
Here is the code:
class Point:
""" Define a Point
"""
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def __str__(self):
return "(" + str(self.x) + "," + str(self.y) + ")"
def __getitem__(self,i):
return i
def __find__(self,j):
return j
def DistanceTo(self,p2):
idx1 = p2.find("(")
idx2 = p2.find(",")
idx3 = p2.find(")")
x2 = int(p2[idx1+1:idx2])
y2 = int(p2[idx2+1:idx3])
dist = math.sqrt(math.pow((x2-self.x),2)+math.pow((y2-self.y),2))
return dist
p1=Point()
p2=Point(3,4)
print p1.DistanceTo(p2)