Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Keyword Arguments

Reply
Thread Tools

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
 
Reply With Quote
 
 
 
 
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)
 
Reply With Quote
 
 
 
 
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>




 
Reply With Quote
 
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)



 
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
RE: keyword checker - keyword.kwlist Hamilton, William Python 4 05-13-2007 06:31 AM
keyword checker - keyword.kwlist tom@finland.com Python 6 05-10-2007 04:53 PM
Keyword arguments in a block, possible with zero arguments? Peter Motzfeldt Ruby 1 03-13-2007 01:33 PM
Difference between default arguments and keyword arguments Edward Diener Python 14 04-05-2004 11:26 PM
logging module: log method with keyword arguments David Konerding Python 0 09-09-2003 11:40 PM



Advertisments