python - I would call this advanced tuple manipulation? -
i'm trying take list of tuples contain name of individual functions , arguments , instantiate them..this used multi-threading application.
import pandas pd df = pd.dataframe() def func1(df,arg2,arg3): print 'func1' print type(df) print arg2,arg4 def func2(arg1,df,arg3,arg4): print 'func2' print arg1 print type(df) print arg3,arg4 list_of_func_tups = [(func1,df,'two','three'),(func2,'one',df,'three','four')] tup in list_of_func_tups: f = tup[0] args = tup[1:] results = f(args) but problem args still seen tuple, hence, error stating 1 argument given.
typeerror: func1() takes 3 arguments (1 given) is there way can somehow args seen respective individual arguments? maybe type of loop or something? anythin?
what looking way feed tuple positional arguments. can using leading asterisk (*):
result = f(*args) this documented in documentation of function calls:
if syntax
*expressionappears in function call,expressionmust evaluate iterable. elements iterable treated if additional positional arguments; if there positional arguments x1,..., xn, , expression evaluates sequence y1, ..., ym, equivalent call m+n positional arguments x1, ..., xn, y1, ..., ym.
Comments
Post a Comment