Python convert list string to list

http://stackoverflow.com/questions/1894269/convert-string-representation-of-list-to-list-in-python

 

>>> import ast >>> x = u'[ "A","B","C" , " D"]' >>> x = ast.literal_eval(x) >>> x ['A', 'B', 'C', ' D'] >>> x = [n.strip() for n in x] >>> x ['A', 'B', 'C', 'D']

你可能感兴趣的:(Python convert list string to list)