It's really odd but I have this string:
"['please', 'help']"
I want something that would get one argument at a time. I've searched everywhere for this but I didn't find anything.
Thanks in advance
It's really odd but I have this string:
"['please', 'help']"
I want something that would get one argument at a time. I've searched everywhere for this but I didn't find anything.
Thanks in advance
While eval
is a correct approach, it can often have negative consequences. I suggest using ast.literal_eval
, which is a more safe approach (as mentioned by the linked docs):
import ast
s = "['please', 'help']"
s_list = ast.literal_eval(s)
print s_list
Are you looking for something like this?
string = "['please', 'help']"
string_list = eval(string)
print string_list[0], string_list[1]
Edit: you should ideally use ast.literal_eval
as the other answer suggests, if you are unsure of what the string contains.