Is there a way to add parameters dynamically when calling a function? For example:
def getParameters(num): parray = [i for i in range(num)] params = tuple(parray) return paramsdef func(*args, **kwargs): pass
Each time, when calling the function func
, the number of parameters is decided by the function getParameters
, which is unknown until the code is executed.
For example, in the code, someone may do this:
param1 = getParameters(2)# they wants to use param1 to the func# which would be func(1, 2)param2 = getParameters(6)# Likewise, this would be func(1, 2, 3, 4, 5, 6)
But I can't directly pass the tuple to the function, Python would treat it as a single parameter in that way.
Since the *args
is a tuple, which contains those extra parameters, is there a way to replace *args
with param1
(also, the same thing to **kwargs
)?