Convert string represent list to list

"ABC"转成 list 格式只要list("ABC")就会得到["A", "B", "C"]
但如果需要把string格式的list转换成list呢?
如把

x = u'[ "A","B","C" , " D"]'

转成

x = ["A", "B", "C", "D"] 

ast

>>> 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']

你可能感兴趣的:(Convert string represent list to list)