Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Problem with Overloading Comparison Operators. #817
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)