Reflected Greater Than Magic Methods
I am in need of a reflected magic method 'greater than' and there does not appear to be one. Here is the situation. I have a class which keeps track of units. It is call Property.
Solution 1:
You can use a functools.total_ordering
decorator to create the missing comparison methods for you:
import functools
@functools.total_ordering
class Property():
...
Then you get False, False, False. Do make sure to read its documentation, though.
Solution 2:
__lt__
is __gt__
's counterpart; you'll need to implement __lt__
. While you're at it, you should probably implement __le__
and __ge__
.
Solution 3:
Since you've declared the __float__()
method, you could always write it as:
print float(y) > float(x)
Post a Comment for "Reflected Greater Than Magic Methods"