python怎么读文件快
收起
云计算小粉
2018-05-10 20:10:10
1378
0
1
条回答
写回答
取消
提交回答
-
def readInChunks(fileObj, chunkSize=4096):
"""
Lazy function to read a file piece by piece.
Default chunk size: 4kB.
"""
while 1:
data = fileObj.read(chunkSize)
if not data:
break
yield data
f = open('bigFile')
for chuck in readInChunks(f):
#do_something(chunk)
f.close()
2019-07-17 22:20:15