> 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? Aargh. I *think* this may have to do with the hacks for sequence repetition. But I'm not sure. A debug session tracing carefully through the code is in order. --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4