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

后端 未结 4 1494
花落未央
花落未央 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:31

    An answer has already been accepted, but I just wanted to add this for the record. The json module is really good for this kind of thing:

    import json
    s = '[24, 72, 95, 100, 59, 80, 87]\n'
    lst = json.loads(s)
    

提交回复
热议问题