Overloading operators on the rigth.

denis wendum wendum.denis at pasdepourriels.edf.fr
Tue Oct 12 15:15:19 CEST 2004


In a nutshell:
What is the equivalent of __radd__ (wich overloads the right hand side
of +) when overloading the comparison operators <,>,== and so on. My
first guess __rlt__ for
overloading the rigth hand side of < did not work.
Expanded version:
In a class of numbers I have been able to overload the four arithmetic
operators +,-,* and / by defining the methods __add__ and __radd__
(etc..) in my class. This enables me to evaluate expressions
"instance_of_my_class+"instance_of_my_class" ,"instance + non_instance"
(with __add__) as well as "non_instance+instance"(with __radd__).
But my guess to define the method __rlt__ in my class in order to be
able to evaluate expressions "non_instance < instance" did not work.
So what are the names (if they exist at all) of the comparison operators
<,>,== and so on,  when one wants to exend their rigth hand side to a
user defined (instance of a) class?

In case of direct e-mail response please remove the french translation
of nospam in my signature, that is to say the string  :
pasdepourriels.




More information about the Python-list mailing list