In Python, is read() , or readlines() faster?

后端 未结 8 1663
醉酒成梦
醉酒成梦 2020-11-30 05:50

I want to read a huge file in my code. Is read() or readline() faster for this. How about the loop:

for line in fileHandle
8条回答
  •  盖世英雄少女心
    2020-11-30 06:37

    The real difference between read() and readlines() The read function simply loads the file as is into memory. The readlines method reads the file as a list of lines without line termination. The readlines method should only be used on text files, and neither should be used on large files. If copying the information from a text file, read works well, because it can be output with a the write function without the need to add line termination.

提交回复
热议问题