Passing parameters to functions

Thomas Philips tkpmep at hotmail.com
Tue May 25 19:54:30 EDT 2004


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'

For the reasons you outlined earlier, the alternate form 
f(1, 2,karg1="maybe", karg2="maybe not", 3, 4, 5, m="yes", n="no")
generates a syntax error. 

How can I pass all these arguments into the function cleanly?

Thomas Philips



More information about the Python-list mailing list