Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Probably nothing remotely resembling this belongs in anything remotely resembling production code, but:

  In [1]: class Foo:
     ...:     def __rmul__(self, other):
     ...:         print("%s foos!" % other)
     ...:
  
  In [2]: .42 * Foo()
  0.42 foos!


That's very nice. I tried to go for such an example originally but I only tried __mul__ because I thought it's like in Lua where __mul gets used even if only the second operand has a custom one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: