Convert \r text to \n so readlines() works as intended

前端 未结 2 730
迷失自我
迷失自我 2021-01-01 17:49

In Python, you can read a file and load its lines into a list by using

f = open(\'file.txt\',\'r\')
lines = f.readlines()

Each individual l

2条回答
  •  生来不讨喜
    2021-01-01 18:23

    f = open('file.txt','rU')
    

    This opens the file with Python's universal newline support and \r is treated as an end-of-line.

提交回复
热议问题