Was: Is this an Bug in python 2.3?? Reflective relational operators

Balaji balaji at email.arizona.edu
Mon Jun 14 23:15:12 EDT 2004


Hello Everybody...

Here is a code (tested)

class Test:

        def __le__(self,other):
                print " <= "
        def __ge__(self,other):
                print " >= "
        def __add__(self,other):
                print " + "
        def __radd__(self,other):
                print " r+ "


Suppose s is an instance of Test.

s=Test()

s>=100

prints >=

but 100>=s

prints <=

The point here is mathematically it is right but not modelling wise.

By modelling I mean, the user wants to preserve the order in which he
typed the
expression.

Is there a way to obtain the radd behavior in __ge__ and __le__ with
current syntax..

Regards

Balaji



More information about the Python-list mailing list