How to read a large file - line by line?

前端 未结 11 855
一整个雨季
一整个雨季 2020-11-21 11:44

I want to iterate over each line of an entire file. One way to do this is by reading the entire file, saving it to a list, then going over the line of interest. This method

11条回答
  •  伪装坚强ぢ
    2020-11-21 12:00

    Best way to read large file, line by line is to use python enumerate function

    with open(file_name, "rU") as read_file:
        for i, row in enumerate(read_file, 1):
            #do something
            #i in line of that line
            #row containts all data of that line
    

提交回复
热议问题