Is __mul__ sufficient for operator '*'?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Oct 19 23:31:07 EDT 2009


En Mon, 19 Oct 2009 21:31:44 -0300, Muhammad Alkarouri  
<malkarouri at gmail.com> escribió:

> I was having a go at a simple implementation of Maybe in Python when I
> stumbled on a case where x.__mul__(y) is defined while x*y is not.

__special__ methods are searched in the type, not in the instance  
directly. x*y looks for type(x).__mul__ (among other things)


-- 
Gabriel Genellina




More information about the Python-list mailing list