Velocity Reviews > Keyword Arguments

# Keyword Arguments

Ryan
Guest
Posts: n/a

 11-14-2003
How can I use the value of a variable to represent a keyword in a function call?

For example:

def foo(**kwargs):
kwargs = **kwargs

item = "temperature"

foo(item=25.5)

I would like the keyword to be the value of item which is temperature.
Is this possible?

Thanks
Ryan

Paul Rubin
Guest
Posts: n/a

 11-14-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Ryan) writes:
> How can I use the value of a variable to represent a keyword in a
> function call?
>
> For example:
>
> def foo(**kwargs):
> kwargs = **kwargs
>
> item = "temperature"
>
> foo(item=25.5)
>
> I would like the keyword to be the value of item which is temperature.
> Is this possible?

You mean you want the equivalent of foo(temperature=25.5)? Try:

args = {item : 25.5}
foo (**args)

Fredrik Lundh
Guest
Posts: n/a

 11-15-2003
"Ryan" wrote:

> How can I use the value of a variable to represent a keyword in a function call?
>
> For example:
>
> def foo(**kwargs):
> kwargs = **kwargs
>
>
> item = "temperature"
>
> foo(item=25.5)
>
> I would like the keyword to be the value of item which is temperature.
> Is this possible?

foo(**{item: 25.5})

</F>

ryan scott
Guest
Posts: n/a

 11-15-2003
Exactly what I wanted.
Thanks

Ryan

Paul Rubin wrote:
> (E-Mail Removed) (Ryan) writes:
>
>>How can I use the value of a variable to represent a keyword in a
>>function call?
>>
>>For example:
>>
>>def foo(**kwargs):
>> kwargs = **kwargs
>>
>>item = "temperature"
>>
>>foo(item=25.5)
>>
>>I would like the keyword to be the value of item which is temperature.
>>Is this possible?

>
>
> You mean you want the equivalent of foo(temperature=25.5)? Try:
>
> args = {item : 25.5}
> foo (**args)