Operator commutativity

Peter Pearson ppearson at nowhere.invalid
Tue Sep 20 19:07:35 CEST 2011


On Mon, 19 Sep 2011 05:48:07 -0700, Ethan Furman <ethan at stoneleaf.us> wrote:
[snip]
> Also, if the right-hand operand is a subclass of the left-hand operand 
> then Python will try right-hand_operand.__radd__ first.

I don't think it works that way for me:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
>>> class C1():
...     def __add__(self, other):
...         print "C1.__add__()"
... 
>>> class C2(C1):
...     def __radd__(self, other):
...         print "C2.__radd__()"
... 
>>> C1() + C2()
C1.__add__()
>>> 


-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list