Merge pull request #15 from nasyxx/patch-2

Fixes #8
master
kenwoodjw 2019-03-05 21:15:00 +08:00 committed by GitHub
commit fc30a00ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -291,11 +291,9 @@
现在要处理一个大小为10G的文件但是内存只有4G如果在只修改get_lines 函数而其他代码保持不变的情况下,应该如何实现?需要考虑的问题都有那些?
```
def get_lines():
l = []
with open('file.txt','rb') as f:
data = f.readlines(60000)
l.append(data)
yield l
for l in f:
yield l
```
要考虑的问题有内存只有4G无法一次性读入10G文件需要分批读入分批读入数据要记录每次读入数据的位置。分批每次读取数据的大小太小会在读取操作花费过多时间。
## 1.2 补充缺失的代码