I have a script that reads a variable number of fields from an input file and pass them to a function as arguments. For example:
file 1 with fields: A,B a
Read the fields (arguments) into a list and then use argument unpacking:
function(*fields)
Below is a demonstration:
>>> def func(*args): ... return args ... >>> fields = ["A", "B", "C"] >>> func(*fields) ('A', 'B', 'C') >>> fields = ["A", "B", "C", "D"] >>> func(*fields) ('A', 'B', 'C', 'D') >>>