variable arguments question

V

vegetax

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
 
S

Stephan Diehl

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.
 
R

Roel Schroeven

vegetax said:
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:
(1, 2)
 

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
474,222
Messages
2,571,142
Members
47,756
Latest member
JulienneY0

Latest Threads

Top