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")
0

2 Answers 2

1

You can split your string to list of things:

your_string = "spam, foo, moo"
your_function(*your_string.split(', '))
Sign up to request clarification or add additional context in comments.

7 Comments

Can you pass a list for arguments? I thought that you could only pass a tuple.
Just tested in my interpreter - you can. Thanks!
Of course. @DennysBlake for more information: stackoverflow.com/questions/3961007/…
Just a note : your answer was wrong at first and you modified it after I wrote mine. I'll have better luck next time!
@DennysBlake Fixed.
|
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(', '))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.