By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 1,976 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

variable arguments question

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.