Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Passing variable number of named arguments

Reply
Thread Tools

Passing variable number of named arguments

 
 
Ramashish Baranwal
Guest
Posts: n/a
 
      12-27-2006
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

 
Reply With Quote
 
 
 
 
Carsten Haese
Guest
Posts: n/a
 
      12-27-2006
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


 
Reply With Quote
 
 
 
 
Ramashish Baranwal
Guest
Posts: n/a
 
      12-28-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function that expects variable arguments from a functionwith variable arguments Navaneeth C Programming 4 11-20-2010 05:35 AM
[ANN] rdp-arguments -- named arguments for 1.8 and 1.9! Roger Pack Ruby 2 01-04-2010 02:56 AM
Call again a variadic function (... variable number of arguments)with same arguments that its variadic wrapper moreau.steve@gmail.com C Programming 3 12-31-2008 07:13 AM
functions and arguments.length; passing unknown number of arguments oldyork90 Javascript 10 09-27-2008 03:05 AM
Passing a variable number of arguments to a wrapped function. stephen@theboulets.net Python 5 08-05-2005 07:31 PM



Advertisments