call f(a, *b) with f(*a, **b) ?

bukzor workitharder at gmail.com
Tue May 27 17:49:12 EDT 2008


On May 23, 1:17 pm, bukzor <workithar... at gmail.com> wrote:
> On May 23, 12:35 pm, "inhahe" <inh... at gmail.com> wrote:
>
>
>
> > "
> > I wish this worked:>>> def main(a,b,*argv): pass
> > >>> options['argv'] = argv
> > >>> main(**options)
>
> > TypeError: main() got an unexpected keyword argument 'argv'
> > "
> > -----
> > I was thinking about that exact same thing actually.  Except that I was
> > thinking you might want it like this, otherwise it could be ambiguous:
>
> > >>> def main(a,b,*argv): pass
> > >>> options['*argv'] = argv
> > >>> main(**options)
>
> > Weird I know, to put the * operator inside the string.  I suppose the
> > necessity of doing that just shows why it wasn't implemented in the first
> > place.  But still, it would be neat...
>
> > Also, of course, you could then do
> > main(*argv=[2,3])
>
> > or rather
>
> > main(*argv=[3,4],a=1,b=2) #in random order
>
> Yes I think something like that would be an improvement. I wonder if
> anyone would help me write a PEP... It might not be too hard to pass
> since it would be compatible with all existing code. I'd be willing to
> produce a patch against python2 or py3k.
>
> I don't see that leaving off the * makes it ambiguous, since there can
> only be one argument with that name:
> def f(args, *args): pass
> SyntaxError: duplicate argument 'args' in function definition

I guess that's a no...



More information about the Python-list mailing list