Passing a dictionary to a function in python as keyword parameters -
i'd call function in python using dictionary.
here code:
d = dict(param='test') def f(param): print param f(d) this prints {'param': 'test'} i'd print test.
i'd work more parameters:
d = dict(p1=1, p2=2) def f2(p1,p2): print p1, p2 f2(d) is possible?
figured out myself in end. simple, missing ** operator unpack dictionary
so example becomes:
d = dict(p1=1, p2=2) def f2(p1,p2): print p1, p2 f2(**d)
Comments
Post a Comment