Python: How to remove [' and ']?

前端 未结 4 694
说谎
说谎 2021-01-29 11:36

I want to remove [\' from start and \'] characters from the end of a string.

This is my text:

\"[\'45453656565\']\"
         


        
4条回答
  •  滥情空心
    2021-01-29 11:56

    Instead of hacking your data by stripping brackets, you should edit the script that created it to print out just the numbers. E.g., instead of lazily doing

    output.write(str(mylist))
    

    you can write

    for elt in mylist:
        output.write(elt + "\n")
    

    Then when you read your data back in, it'll contain the numbers (as strings) without any quotes, commas or brackets.

提交回复
热议问题