__iadd__ with 2 args?

Ian Kelly ian.g.kelly at gmail.com
Fri Mar 20 17:33:42 EDT 2015


On Fri, Mar 20, 2015 at 3:25 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> I can write a member
>
> F.__iadd__ (self, *args)
>
> and then call it with 2 args:
>
> f = F()
> f.__iadd__ (a, b)
>
> And then args is:
> (a, b)
>
> But it seems impossible to spell this as
>
> f += a, b
>
> That, instead, results in
>
> args = ((a, b),)
>
> So should I just abandon the idea that += could be used this way?

Is there some reason you need the *? Just have it take one argument
which will be a tuple.

>>> class F:
...   def __iadd__(self, other):
...     print(other)
...
>>> f = F()
>>> f += 1, 2
(1, 2)



More information about the Python-list mailing list