On Mon, 08 Feb 2010 21:59:18 +0100, Martin Drautzburg wrote:

> Just for the hell of it ...
> 
> I can easily define __plus__() with three parameters. If the last one is
> optional the + operation works as expected. Is there a way to pass the
> third argument to "+"

How do you give three operands to a binary operator? Binary operators 
only have two sides, a left and a right, so you can only fit two operands 
around them.

Mathematicians solve this problem by using functions:

add(a, b, c, d)

In Python, you can do this:

>>> class F:
...     def __add__(self, other, foo=None):
...             print self, other, foo
...             return 1
...
>>>
>>> F() + 3
<__main__.F instance at 0xb7f06f4c> 3 None
1
>>> F().__add__(3, 4)
<__main__.F instance at 0xb7f06d8c> 3 4
1



but if you do, people will laugh and point at you in the street.

*wink*


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to