1

If I have a string like:

"spam, foo, moo"

How would I pass that to a function so it would turn into:

myFunction("spam", "moo", "foo")
gusg21
  • 147
  • 11

2 Answers2

1

You can split your string to list of things:

your_string = "spam, foo, moo"
your_function(*your_string.split(', '))
Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67
0

You can split your string and unpack the elements, in order to get 3 arguments.

With just split, you'd get one argument, a list of 3 strings.

myFunction(*"spam, foo, moo".split(', '))
Eric Duminil
  • 52,989
  • 9
  • 71
  • 124