473,378 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Keyword Arguments

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
Jul 18 '05 #1
3 1761
ry*******@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)
Jul 18 '05 #2
Exactly what I wanted.
Thanks

Ryan

Paul Rubin wrote:
ry*******@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)

Jul 18 '05 #3
"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>


Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Roy Smith | last post by:
I've got a function that takes a couple of optional keyword arguments. I want to check to make sure I didn't get passed an argument I didn't expect. Right now I'm doing: conversion = None drop...
3
by: black | last post by:
Hi all~ I met problem when trying passing keyword arguments to derived class. my goal is to pass all keyword arguments to taht derived class as they did for superclass, but the result was not...
14
by: Edward Diener | last post by:
In the tutorial on functions there are sections on default arguments and keyword arguments, yet I don't see the syntactic difference between them. For default arguments the tutorial shows: def...
1
by: Steven Bethard | last post by:
So I've been playing around with trying to add a keyword argument to min and max that works similarly to the one for sorted. It wasn't too hard actually, but it does raise a few questions about...
1
by: Fuzzyman | last post by:
A colleague and I have built a Validator object for use with ConfigObj and other general schema situations. A config file is used to store a schema that specifies how to test a value that it is...
2
by: Fuzzyman | last post by:
Sorry if this is a duplicate - I use the google interface and sometiems it screws up (not showing stuff you've posted *or* not posting it). Before you ask it's because at work I have no NNTP and...
20
by: talin at acm dot org | last post by:
Although I realize the perils of even suggesting polluting the Python namespace with a new keyword, I often think that it would be useful to consider defining an operator for testing whether or not...
2
by: Bo Peng | last post by:
Dear list, The syntax for using assertRaise is assertRaise(exception, function, para1, para2,...) However, I have a long list of arguments (>20) so I would like to test some of them using...
10
by: Armando Serrano Lombillo | last post by:
Why does Python give an error when I try to do this: Traceback (most recent call last): File "<pyshell#40>", line 1, in <module> len(object=) TypeError: len() takes no keyword arguments but...
3
by: Sean DiZazzo | last post by:
Why is the following not working? Is there any way to get keyword arguments working with exposed XMLRPC functions? ~~~~~~~~~~~~~~~~ server.py import SocketServer from SimpleXMLRPCServer import...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.