python call a function with kwargs -


i have function:

def myfunc():     kwargs = {}     = 1     b = 2     kwargs.update(a=a, b=b)     newfunc(**kwargs) 

and newfunc

def newfunc(**kwargs):     print 

its not giving value of 1

whats wrong ?

two things.

first, kwargs argument in myfunc empty dict, won't pass parameters. if want pass value of a , b newfunc, can either use

kwargs = {'a':1, 'b':2} newfunc(**kwargs) 

or

newfunc(a=1, b=2) 

in both cases, 'a' , 'b' in kwargs dict of newfunc function.

second, should extract argument kwargs dict in newfunc. print kwargs.get('a') should suffice.


Comments

Popular posts from this blog

What Are The Best Universities In The World?

Hard vs. Soft Water: What's The Difference?

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -