How convert a list string to a real list

Terry Reedy tjreedy at udel.edu
Wed Nov 30 18:12:14 EST 2011



On 11/30/2011 5:48 PM, Hidura wrote:
> Why you don't make this "['1','2','3']".strip("[]").split(',') work for me

Look more carefully. This is not the same as ast.literal_eval().

 >>> "['1','2','3']".strip("[]").split(',')
["'1'", "'2'", "'3'"]  # list of 3-char strings
 >>> ast.literal_eval("['1','2','3']")
['1', '2', '3']  # list of 1-char strings

Even if it were the same, it would be specific to lists of strings and 
would not work for anything else.



More information about the Python-list mailing list