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
Post a Comment