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)

 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 OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Hamilton, William Python 4 05-13-2007 06:31 AM tom@finland.com Python 6 05-10-2007 04:53 PM Peter Motzfeldt Ruby 1 03-13-2007 01:33 PM Edward Diener Python 14 04-05-2004 11:26 PM David Konerding Python 0 09-09-2003 11:40 PM