Python list string to list

后端 未结 6 1387
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 11:51

I have a string:

s= \"[7, 9, 41, [32, 67]]\"

and I need to convert that string into a list:

l= [7, 9, 41, [32, 67]]
         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 12:41

    Use: package ast: function : literal_eval(node_or_string)

    http://docs.python.org/library/ast.html#module-ast

提交回复
热议问题