Why can't you use varargs and keyword arguments together?

Sandra-24 sandravandale at yahoo.com
Thu Dec 21 17:51:15 EST 2006


I've always wondered why I can't do:

def foo(a,b,c):
    return a,b,c

args = range(2)
foo(*args, c = 2)

When you can do:

foo(*args, **{'c':2})

Whenever I stub my toe on this one, I always just use the second
approach, which seems less readable. As with most things in Python,
I've suspected there's a good reason for it. Having just bumped into
this one again, I thought I'd ask if anyone knows why the first syntax
should not be allowed.

This comes up anyplace you need variable arguments and keyword
arguments together but don't have the keyword arguemnts in a dict. In
this case you are forced to put them in a dict. I don't think anyone
would find that to be more readable.

Thanks and Merry Christmas,
-Sandra




More information about the Python-list mailing list