Passing a string to a function but quotes are causing an issue
Question:
I am trying to pass a string to a function like this and it works fine
players = pool.get_players('Trevor Zegras', 'Adam Henrique', 'Troy Terry', 'Cam Fowler', 'Dmitry Kulikov', 'John Gibson')
However I am trying to pass a variable
like this and it doesn’t work, I think because of extra quotes because of the string.
This returns an error
group = "'Trevor Zegras', 'Adam Henrique', 'Troy Terry', 'Cam Fowler', 'Dmitry Kulikov', 'John Gibson'"
players = pool.get_players(group)
Is there a way to pass it the variable without the quotes? I tried to remove them, but am unable to. I tried a tuple, but that failed as well.
Answers:
Your function doesn’t take one string argument, it takes multiple arguments.
When you use a string as an argument, it’s not parsed into separate arguments; it’s not like a macro that reparsed the result of substituting the string.
Put them in a list, not a string, then use the spread operator to turn them into separate arguments.
group = ['Trevor Zegras', 'Adam Henrique', 'Troy Terry', 'Cam Fowler', 'Dmitry Kulikov', 'John Gibson']
players = pool.get_layers(*group)
I am trying to pass a string to a function like this and it works fine
players = pool.get_players('Trevor Zegras', 'Adam Henrique', 'Troy Terry', 'Cam Fowler', 'Dmitry Kulikov', 'John Gibson')
However I am trying to pass a variable
like this and it doesn’t work, I think because of extra quotes because of the string.
This returns an error
group = "'Trevor Zegras', 'Adam Henrique', 'Troy Terry', 'Cam Fowler', 'Dmitry Kulikov', 'John Gibson'"
players = pool.get_players(group)
Is there a way to pass it the variable without the quotes? I tried to remove them, but am unable to. I tried a tuple, but that failed as well.
Your function doesn’t take one string argument, it takes multiple arguments.
When you use a string as an argument, it’s not parsed into separate arguments; it’s not like a macro that reparsed the result of substituting the string.
Put them in a list, not a string, then use the spread operator to turn them into separate arguments.
group = ['Trevor Zegras', 'Adam Henrique', 'Troy Terry', 'Cam Fowler', 'Dmitry Kulikov', 'John Gibson']
players = pool.get_layers(*group)