On Tue, Jul 8, 2008 at 3:29 PM, Christopher Spears <[EMAIL PROTECTED]> wrote:
> I have been reading everyone's comments on my line class. I have decided > to implement some of the suggestions. Someone suggested that I create a > Point.__cmp__ method. Here is what I have so far: > > def __cmp__(self, other): > if self.x == other.x and self.y == other.y: > return 0 > elif self.x < other.x and self.y < other.y: > return -1 > elif self.x > other.x and self.y > other.y: > return 1 > > Figuring out the results for the above situations was easy. However, what > should I do with the following situations: > self.x > other.x and self.y < other.y > self.x < other.x and self.y > other.y > Sorry to jump in late - I missed the first part of the discussion - but what do you want to achieve with a Point.__cmp__ method? Is it just to determine whether two points are identical - in which case I'd write it like so: def __cmp__(self, other): if (self.x == other.x) and (self.y == other.y): return True else: return False Or are you trying to determine the slope of the line between two points, in which case I'd write it like this: def __cmp__(self, other): if self.x == other.x: return False # points are identical, or one above the other - slope is undefined else: return (self.y - other.y) / (self.x - other.x) # rise over run or... or... or... First decide what you want out of it, then write the function/method to give you the result you want. -- www.fsrtechnologies.com
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor