Forwarding keyword arguments from one function to another

Tim Wintle tim.wintle at teamrubber.com
Sun Feb 22 14:52:13 EST 2009


On Sun, 2009-02-22 at 11:44 -0800, Ravi wrote:
> The following code didn't work:
> 
<snip>
>         def g(self, s, kwds):
>                 print s
>                 print kwds

This expects the function g to be called with the parameters "s" and
"kwds"

<snip>
>         def g(self, s, **kwds):
>                 print s
>                 print kwds

This expects to be passed the parameter "s", and various keyword
arguments, which will be put into the dict "kwds".

when you call 

o.g("string",**kwds)

you are passing the parameter "string" as the first parameter, and then
a sequence of keyword arguments taken from kwds, which will be passed
separately.

This is what the second form expects, but not what the first one
expects.

Tim Wintle





More information about the Python-list mailing list