File tree Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change 291
291
现在要处理一个大小为10G的文件,但是内存只有4G,如果在只修改get_lines 函数而其他代码保持不变的情况下,应该如何实现?需要考虑的问题都有那些?
292
292
```
293
293
def get_lines():
294
- l = []
295
294
with open('file.txt','rb') as f:
296
- data = f.readlines(60000)
297
- l.append(data)
298
- yield l
295
+ for l in f:
296
+ yield l
299
297
```
300
298
要考虑的问题有:内存只有4G无法一次性读入10G文件,需要分批读入分批读入数据要记录每次读入数据的位置。分批每次读取数据的大小,太小会在读取操作花费过多时间。
301
299
## 1.2 补充缺失的代码
@@ -1136,4 +1134,4 @@ Web browsable API对开发者有极大的好处
1136
1134
支持ORM和非ORM数据资源的序列化
1137
1135
全程自定义开发--如果不想使用更加强大的功能,可仅仅使用常规的function-based views额外的文档和强大的社区支持
1138
1136
## 2.19 对cookies与session的了解?他们能单独用吗?
1139
- Session采用的是在服务器端保持状态的方案,而Cookie采用的是在客户端保持状态的方案。但是禁用Cooki就不能得到Session。因为Session是用Session ID来确定当前对话所对应的服务器Session,而Session ID是通过Cookie来传递的,禁用Cookie相当于SessionID,也就得不到Session。
1137
+ Session采用的是在服务器端保持状态的方案,而Cookie采用的是在客户端保持状态的方案。但是禁用Cooki就不能得到Session。因为Session是用Session ID来确定当前对话所对应的服务器Session,而Session ID是通过Cookie来传递的,禁用Cookie相当于SessionID,也就得不到Session。
You can’t perform that action at this time.
0 commit comments