rh0dium schrieb: > Hi Experts!! > > I am trying to get the following little snippet to push my data to the > function func(). What I would expect to happen is it to print out the > contents of a and loglevel. But it's not working. Can someone please > help me out. > > ---------<snip>-------------- > #!/usr/bin/env python > > import random > > def func(*args, **kwargs): > print kwargs.get('a', "NOPE") > print kwargs.get('loglevel', "NO WAY") > > def main(): > b = [] > for x in range(5): > b.append({'a':random.random(), "loglevel":10}) > > for y in b: > apply(func,y) > > # First attempt - didn't work > # for y in b: > # func(y) > > if __name__ == '__main__': > main() > ``apply()`` is deprecated -- use the asterisk-syntax_ instead.
>>>> dic = {'a': 5, 'loglevel': 10} >>> def foo(*args, **kwargs): ... print kwargs ... >>> foo(**dic) {'a': 5, 'loglevel': 10} So, your first attempt was close -- just two signs missing. :-) HTH, Stargaming .. _asterisk-sytax: http://docs.python.org/tut/node6.html#SECTION006740000000000000000 -- http://mail.python.org/mailman/listinfo/python-list