Keyword Arguments

R

Ryan

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
 
P

Paul Rubin

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)
 
F

Fredrik Lundh

Ryan said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top