Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Overloading Comparison Operators. #817

Open
chetweger opened this issue Feb 26, 2014 · 0 comments

Comments

@chetweger
Copy link

commented Feb 26, 2014

Output from the python terminal is different than output from the firefox web console.

The values for max(ll) and max(lll) are correct; only max(l).value is incorrect (differs between python and the browser). This would suggest a problem with overriding the comparison operators in my Util class.

class Util:
  def __init__(self, value):
    self.value = value
  def __ge__(self, other):
    return self.value >= other.value
  def __le__(self, other):
    return self.value <= other.value
  def __gt__(self, other):
    return self.value > other.value
  def __lt__(self, other):
    return self.value < other.value



l = [Util(3), Util(1), Util(9), Util(-1)]
ll = [3, 1, 9, -1]
lll = [(3, ''), (1, ''), (9, ''), (-1, '')]

print "Should be 9 ", max(l).value
print "Should be 9 ", max(ll)
print "Should be (9, '') ", max(lll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.