8 Aug
2002
8 Aug
'02
1:46 p.m.
Suppose that a new-style class wants to overload "*" and it defines two methods like this: class Foo(object): def __mul__(self,other): print "__mul__" def __rmul__(self,other): print "__rmul__" Python-2.2.1, if you try this, you get the following behavior:
f = Foo() f*1.0 __mul__ 1.0*f __rmul__ f*1 __mul__ 1*f __mul__
So here is the question: Why does the last statement in this example not invoke __rmul__? In other words, why do "1.0*f" and "1*f" produce different behavior. Is this intentional? Is this documented someplace? Is there a workaround? Or are we just missing something obvious? Cheers, Dave