How to Expanding tuples into arguments?
How to Expanding tuples into arguments?
Use myfun(*tuple) to Expanding tuples into arguments.
Drawbacks:don’t use for identifiers builtin type names such as tuple, list, file, set, and so forth — it’s horrible practice and it will come back and bite at the least expect time, so just get into the habit of actively avoiding hiding builtin names with the own identifiers.
Use this code:
myfun(1, *("foo", "bar"))
Note:It is possible to expand part of argument list.
Try this code to Expanding tuples into arguments:
def run_argtup(func, argvalues): """ Execute any functions with their arguments in tuple. :param func: :param argvalues: :return: """ argnames = get_func_argnames(func) if len(argnames) != len(argvalues): raise ValueError("Length of args doens't match.") for argn, argv in zip(argnames, argvalues): exec('{}=argv'.format(argn)) return eval('func(%s, %s)' % argnames)