You can filter the kwargs
dictionary based on func_code.co_varnames
(in python 2) of a function:
def skit(*lines, **kwargs):
for line in lines:
line(**{key: value for key, value in kwargs.iteritems()
if key in line.func_code.co_varnames})
In python 3, __code__
should be used instead of func_code
. So the function will be:
def skit(*lines, **kwargs):
for line in lines:
line(**{key: value for key, value in kwargs.iteritems()
if key in line.__code__.co_varnames})
Also see: Can you list the keyword arguments a function receives?