How to turn a 'string list' into a real list?

后端 未结 4 1537
花落未央
花落未央 2021-01-25 19:42

I am opening a .txt file and have to use a list inside of it for a function I am writing. This is one of the lists given in the text file:

\'[24, 72         


        
4条回答
  •  庸人自扰
    2021-01-25 20:38

    Use ast.literal_eval:

    strs='[24, 72, 95, 100, 59, 80, 87]\n'
    list_of_strs = ast.literal_eval(strs)
    

    Further help, leave a comment....

提交回复
热议问题