A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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.
anonymous
 5 years ago
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.

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0the functions that use the __functionname__ convention mostly deal with operator overloadingthat 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Thanks for your explanation. I now understand how the things relate to each other and what they mean.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0It 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Sorry, link should be http://docs.python.org/reference/datamodel.html

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Thanks for the reference, just what I needed to get a better understanding of lecture 15.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.