covert a string which is a list into a proper list python

前端 未结 2 1025
挽巷
挽巷 2020-12-04 02:00

How do I convert this string which is a list into a proper list?

mylist = \"[\'KYS_Q5Aa8\', \'KYS_Q5Aa9\']\"

I tired this but its not what

2条回答
  •  遥遥无期
    2020-12-04 02:18

    you can use json library and it's more efficient than eval.

    import json
    mylist = "['KYS_Q5Aa8', 'KYS_Q5Aa9']"
    mylist = json.loads(mylist.replace("'",'\"'))
    

提交回复
热议问题