Can Python remove double quotes from a string, when reading in text file?

后端 未结 9 2114
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 04:30

I have some text file like this, with several 5000 lines:

5.6  4.5  6.8  \"6.5\" (new line)
5.4  8.3  1.2  \"9.3\" (new line)

so the last t

9条回答
  •  攒了一身酷
    2020-12-29 05:06

    I think the easiest and most efficient thing to do would be to slice it!

    From your code:

    d = l[3]
    returns "6.5"
    

    so you simply add another statement:

    d = d[1:-1]
    

    now it will return 6.5 without the leading and end double quotes.

    viola! :)

提交回复
热议问题