Passing parameters to functions
Holger Türk
htx1 at gmx.de
Wed May 26 04:39:18 EDT 2004
Thomas Philips wrote:
> Thanks for the explanation. A follow up question: Suppose I want to
> pass AT LEAST 2 positional arguments and AT LEAST 2 keyword arguments
> into a function, Then I think I would logically define the function as
> follows
>
> def f(parg1, parg2, karg1="yes", karg2="no", *pargs, **kargs):
> print parg1, parg2, pargs, karg1, karg2, kargs
>
> and I expect that
> f(1, 2, 3, 4, 5, karg1="maybe", karg2="maybe not", m="yes", n="no")
>
> will return
> 1 2 (3, 4, 5) "maybe" "maybe not" {'m': "yes", 'n': "no"}
>
> But instead I get an error:
> f() got multiple values for keyword argument 'karg1'
>
> [...]
>
> How can I pass all these arguments into the function cleanly?
Maybe this way:
f (1, 2, karg1="maybe", karg2="maybe not", m="yes", n="no", *[3, 4, 5])
Greeting,
Holger
More information about the Python-list
mailing list