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

后端 未结 8 1624
醉酒成梦
醉酒成梦 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:48

    Neither. Both of them will read the content into memory. In case of big files, iterating over the file object only loads one line of your file at a time and is perhaps a good way to deal with the contents of a huge file.

提交回复
热议问题