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

前端 未结 2 1939
孤街浪徒
孤街浪徒 2021-01-01 17:36

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:04

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

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

提交回复
热议问题