你可以ast.literal_eval
在这里使用:
In [6]: strs="[1,2,3,4]"
In [7]: from ast import literal_eval
In [9]: literal_eval(strs)
Out[9]: [1, 2, 3, 4]
帮助(literal_eval):
In [10]: literal_eval?
Type: function
String Form:<function literal_eval at 0x8cb7534>
File: /usr/lib/python2.7/ast.py
Definition: literal_eval(node_or_string)
Docstring:
Safely evaluate an expression node or a string containing a Python
expression. The string or node provided may only consist of the following
Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
and None.