Passing variable number of named arguments

R

Ramashish Baranwal

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
 
C

Carsten Haese

[...]
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
 
R

Ramashish Baranwal

Carsten said:
[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top