0

I'm using a function that manipulates values in certain way, based on the other values that I pass to it. Example

return foo(a,b)
>>> a_new, b_new

or

return foo(a,b,c)
>>> a_new, b_new, c_new

The function foo is part of a library that cannot be altered. The variables are generated in a loop a step earlier, and, therefore, are just part of a list. So currently, I'm passing the values manually:

return foo(variables[0], variables[1], variables[2])
>>> variables

This is quite a drag. How can I code it, so that all the entries in this list are just spelled out and separated by values? So basically a function:

def bar(variables):
    ???
    return variables[0], variables[1], ... variables[len(variables)]

so I can just

return foo(bar(variables)
>>> variables
cheesus
  • 1,111
  • 1
  • 16
  • 44
  • 1
    Have you tried `return ...variables`? – goodvibration Oct 29 '19 at 10:21
  • 1
    Sorry, that's Javascript... Have you tried `*variables`? – goodvibration Oct 29 '19 at 10:23
  • FYI, your approach with `foo(bar(variables))` is fundamentally flawed. `bar` could also only return one single value and pass it to `foo`. E.g. it could be rewritten to `baz = bar(variables); foo(baz)`—the exact same thing you already have. `bar` can't generate source code which is then evaluated again, that's not how this works… – deceze Oct 29 '19 at 10:29

0 Answers0