arguments to functions

Uwe Mayer merkosh at hadiko.de
Sun Jun 30 21:52:10 EDT 2002


hi,

I wanted to pass one named and a collection of unnamed (an arbitrary 
number) to a function:

def test(expected=None, *misc):
    print(expected)
    print(misc)

Now, unluckyly 'test' interprets the first unnamed parameter to test as 
the value for 'expected':

test(5, expected=10)
TypeError: test() got multiple values for keyword argument 'expected'

on the other side any keyword arguments must follow non-keyword 
arguments:

test(expected=5, 10)
SyntaxError: non-keyword arg after keyword arg

Which is a pitty, because I think this version is clear.

Is that *it*, or am I doing something wrong here?

Thanks
Uwe



More information about the Python-list mailing list