I have a function that takes as input *args
:
def foo(*args):
for a in args:
print(a)
This works as intended
> foo('a', 'b')
> a
> b
I am faced with a situation where I don't know how many args are going to be passed (which is the whole point of args
), but I don't know how to create a "list of positional arguments" to be passed to the function.
Part of the challenge is to appropriately phrase the question..
Let me try with an example: the function may be called as foo('a')
or it may be called as foo('a', 'b', 'c', 'd', 'e')
but I don't know because this function is being called by another class that creates the list of unknown number of parameters.
Essentially I want to create a variable containing the parameters like so:
positional_arguments = ('a','b','c')
so that the function can be called like foo(positional_arguments)
.
This however does not work as it does not correctly unpack positional_arguments
:
> foo(positional_parameters)
> ('a', 'b', 'c')
but what I want is
> foo(positional_parameters)
> a
> b
> c