Extra comma (was Re: For review: PEP 308 - If-then-else expression)

Andrew Dalke adalke at mindspring.com
Tue Feb 11 17:20:11 EST 2003


Russell E. Owen
> And why
> can't a function be called with multiple *-marked lists and/or **-marked
> dictionaries, e.g.:
> foo(arg1, *argList1, *argList2)?
>
> I realize that calling a function with * and ** args was added to mimic
> its use in function definitions, for which the "only one of each"
> restriction makes sense. But when calling a function? It'd be handy at
> times.

I do not know why.  However, when it is handy, it can usually be
replaced with a +, as in

   foo(arg1, *(argList1+argList2))

The exceptions are when you mix list and tuple so need an
explicit conversion to one.  Ditto for if one of those is an
iterator.

OTOH, this would work too

def concat(*generators):
  for gen in generators:
    for x in gen:
      yield gen

foo(arg1, *concat(argList1, argList2, ...))

I believe there is also a iterator utilities package which
includes a bunch of these sorts of functions.  Perhaps
in the Python sandbox of CVS?

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list