Keyword Arguments

Paul Rubin http
Fri Nov 14 16:58:44 EST 2003


ryanscott at trentu.ca (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)




More information about the Python-list mailing list