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

后端 未结 8 1666
醉酒成梦
醉酒成梦 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条回答
  •  猫巷女王i
    2020-11-30 06:22

    If your file is a text file then use readlines() which is obviously the way to read file containing lines. Apart from that: perform benchmarks if you are really aware of possible performance problems. I doubt that you will encounter any issues....the speed of the filesystem should be the limiting factor.

提交回复
热议问题