def call_function(fn, args):
    argspec = inspect.getargspec(fn)
arglist = {}
for arg in argspec.args:
    if arg in list(args.__dict__.keys()) and args.__dict__[arg] is not None:
        arglist[arg] = args.__dict__[arg]
return fn(**arglist)
Conditional passing of arguments to methods in python