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']
posted @ 2016-01-23 20:34  藥師  阅读(732)  评论(0编辑  收藏  举报