473,324 Members | 2,246 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,324 software developers and data experts.

variable arguments question

if i have a dictionary:
d = {'a':2,'b':3 }
l = (1,2)

how can i pass it to a generic function that takes variable keywords as
arguments? same thing with variable arguments, i need to pass a list of
arguments to the function

def asd(**kw): print kw
def efg(*arg): print arg

asd(d)
doesnt work
asd(kw = d)
doesnt work

efg(l)
doesnt work

i need to pass those as a dictionary and a list,since i dont know ahead of
time if which items would have d and l

Jul 18 '05 #1
2 1727
On Tue, 15 Mar 2005 03:48:40 -0400, vegetax wrote:
if i have a dictionary:
d = {'a':2,'b':3 }
l = (1,2)

how can i pass it to a generic function that takes variable keywords as
arguments? same thing with variable arguments, i need to pass a list of
arguments to the function

def asd(**kw): print kw
def efg(*arg): print arg

asd(d)
doesnt work
asd(kw = d)
doesnt work
but asd(**d)

efg(l)
doesnt work
and efg(*l)

will work.
i need to pass those as a dictionary and a list,since i dont know ahead of
time if which items would have d and l


Jul 18 '05 #2
vegetax wrote:
if i have a dictionary:
d = {'a':2,'b':3 }
l = (1,2)

how can i pass it to a generic function that takes variable keywords as
arguments? same thing with variable arguments, i need to pass a list of
arguments to the function

def asd(**kw): print kw
def efg(*arg): print arg

i need to pass those as a dictionary and a list,since i dont know ahead of
time if which items would have d and l


You can call them with a syntax resembling the way you defined them:
asd(**d) {'a': 2, 'b': 3} efg(*l)

(1, 2)
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Jul 18 '05 #3

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

Similar topics

7
by: | last post by:
How to call a function with variable argument list from another function again with variable argument list? Example : double average ( int num, ... ); double AFunct1 ( int num, ... ); double...
3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
10
by: The Directive | last post by:
I read the C FAQ question on passing a variable number of arguments, but it didn't help. The example assumes all arguments are of the same type. I want to create a function "trace" that can be...
2
by: EricLin | last post by:
Dear all: I am just concerned about how to use a function with variable number of arguments. for example: int TestFunction(arguments) { .... Testing contents... }
5
by: Jonathan Burd | last post by:
Greetings everyone, I wrote a function to learn about variable-length argument lists. I wonder if there is a better way to detect the end of the argument list than using a sentinel value like...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
1
by: sphinx.moro | last post by:
Hello, I have a function which is coded to receive an unknown number of arguments void Process(int i_ss, int Nerr, ...) { va_list pa; /* variable argument list*/ va_start(pa,...
6
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.