I just watched lecture 15 and wonder why p > q calls cPoint's __cmp__ function. I'd expect p > q check whether p's referent is greater than q's referent. For __cmp__ to be called I'd expect to use dot notation.
the functions that use the __functionname__ convention mostly deal with operator overloading--that is, how the + sign and other operators behave differently depending on whether you're working with strings, ints, or other data types. The __cmp__ function definition for a class defines how the instances of the class will be compared to each other in terms of >, <, and ==. It's kind of hard to see that with the cPoint data type because while __cmp__ is supposed to return different things depending on whether one value is greater than, equal to, or less than the other, it's hard as far as I know for one point to be meaninfully "greater than" or "less than" another.
Thanks for your explanation. I now understand how the things relate to each other and what they mean.
It would also be good to check out ( http://docs.python.org/reference/datamodel.html). That also includes "rich comparison" methods, which are ways to control the behaviors of the individual comparison operators: < > == etc.
Thanks for the reference, just what I needed to get a better understanding of lecture 15.
Join our real-time social learning platform and learn together with your friends!