Consider the following Python code:
def f(*args):
for a in args:
pass
foo = [\'foo\', \'bar\', \'baz\']
# Python generator expressions FTW
gen
Why not look and see what gen
is in f()
? Add print args
as the first line. If it's still a generator object, it'll tell you. I would expect the argument unpacking to turn it into a tuple.
Your don't really need
gen = (f for f in foo)
Calling
f(*foo)
will output
('foo', 'bar', 'baz')
The generator is expanded at the time of the function call, as you can easily check:
def f(*args):
print(args)
foo = ['foo', 'bar', 'baz']
gen = (f for f in foo)
f(*gen)
will print
('foo', 'bar', 'baz')