On Tue, Jul 8, 2008 at 6: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
It might be easier to define __eq__ and __ne__ instead of __cmp__ if you just want to test for equality. Otherwise you can pick an arbitrary ordering or see if there is something that makes sense to the rest of your application. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor