Let\'s say I have a function:
def foo(a=None, b=None, c=None):
return \"a:%s, b:%s, c:%s\" % (a, b, c)
I have a dictionary with some (or
@Ashwini Chaudhary has a very pythonic way of solving your problem. However, it requires changing the signature of your foo function.
If you don't want to change your function signature, you can use introspection to find out what arguments your function expects:
arg_count = foo.func_code.co_argcount
args = foo.func_code.co_varnames[:arg_count]
args_dict = {}
for k, v in d.iteritems():
if k in args:
args_dict[k] = v
foo(**args_dict)