Convert String to List in Python Without Using Eval?

前端 未结 4 1230
粉色の甜心
粉色の甜心 2020-12-21 05:15

I have a string, something like this: \"[[\'Cheese\', 72], [\'Milk\', 45], [\'Bread\', 22]]\".

I want to convert this to a list. I know I can use eval(s

4条回答
  •  Happy的楠姐
    2020-12-21 06:03

    You might consider using the json module to deserialize and making sure your strings are in json format.

    See http://docs.python.org/2/library/json.html for details about using this module.

提交回复
热议问题