Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing a string to a function but quotes are causing an issue

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading