By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Passing variable number of named arguments

P: n/a
Hi,

I need to process few out of a variable number of named arguments in a
function and pass the remaining to another function that also takes
variable number of named arguments. Consider this simple example,

def fun1(**kwargs):
print kwargs.keys()

def fun2(**kwargs):
# get id param
id = kwargs.pop('id', '')
# pass on remaining to fun1
fun1(kwargs)

When I try to call fun2 I get the following error-

TypeError: fun1() takes exactly 0 arguments (1 given)

It seems that the arguments are not passed to fun1 as named arguments.
How can I go about this? Using a dictionary in place of kwargs would be
a way, but I can't modify fun1, so thats ruled out for me.

Thanks,
Ram

Dec 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 2006-12-27 at 10:37 -0800, Ramashish Baranwal wrote:
>[...]
def fun2(**kwargs):
# get id param
id = kwargs.pop('id', '')
# pass on remaining to fun1
fun1(kwargs)

When I try to call fun2 I get the following error-

TypeError: fun1() takes exactly 0 arguments (1 given)

It seems that the arguments are not passed to fun1 as named arguments.
You have to call fun1 like this: fun1(**kwargs).

-Carsten
Dec 27 '06 #2

P: n/a
Carsten Haese wrote:
On Wed, 2006-12-27 at 10:37 -0800, Ramashish Baranwal wrote:
[...]
def fun2(**kwargs):
# get id param
id = kwargs.pop('id', '')
# pass on remaining to fun1
fun1(kwargs)

When I try to call fun2 I get the following error-

TypeError: fun1() takes exactly 0 arguments (1 given)

It seems that the arguments are not passed to fun1 as named arguments.

You have to call fun1 like this: fun1(**kwargs).
Wow. thanks Carsten..

-Ram

Dec 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.