[Python-ideas] Is there a good reason to use * for multiplication?

Steven D'Aprano steve at pearwood.info
Sat Oct 13 10:18:12 CEST 2012

On 13/10/12 19:05, Yuval Greenfield wrote:

> A PEP for defining operators sounds interesting for 4.0 indeed. Though it
> might be messy to allow a module to meddle with the python syntax.

You mean more than classes already do? :)

> Perhaps instead I would like it if all operators were objects with e.g.
> special __infix__ methods.

I believe that Haskell treats operators as if they were function objects,
so you could do something like:

negative_values = map(-, values)

but I think that puts the emphasis on the wrong thing. If (and that's a big
if) we did something like this, it should be a pair of methods __op__ and
the right-hand version __rop__ which get called on the *operands*, not the
operator/function object:

def __op__(self, other, symbol)


More information about the Python-ideas mailing list