问题描述
HI -
很抱歉可能是一个太简单的问题,但我用Google搜索并检查了我的
参考O''Reilly学习Python
书,我没有找到满意的答案。
当我使用readlines时,如果行数很大会怎么样?我有
a非常大的文件(4GB)我想
读入,但我肯定必须对readlines有一些限制我会
想知道python是如何处理的。
我这样使用它:
slines = infile.readlines()#读取所有行到一个名为
" slines"
的字符串列表感谢所有知道这个答案的人。
HI -
Sorry for maybe a too simple a question but I googled and also checked my
reference O''Reilly Learning Python
book and I did not find a satisfactory answer.
When I use readlines, what happens if the number of lines is huge? I have
a very big file (4GB) I want to
read in, but I''m sure there must be some limitation to readlines and I''d
like to know how it is handled by python.
I am using it like this:
slines = infile.readlines() # reads all lines into a list of strings called
"slines"
Thanks for anyone who knows the answer to this one.
推荐答案
关于''文件''类型方法的文档描述了
''readlines''方法,并解决了这个问题。
< URL:http ://docs.python.org/lib/bltin-file-objects.html#l2h-244>
-
\如果你不是解决方案的一部分,你是|
` \沉淀物的一部分。 - Steven Wright |
_o__)|
Ben Finney
The documentation on methods of the ''file'' type describes the
''readlines'' method, and addresses this concern.
<URL:http://docs.python.org/lib/bltin-file-objects.html#l2h-244>
--
\ "If you''re not part of the solution, you''re part of the |
`\ precipitate." -- Steven Wright |
_o__) |
Ben Finney
这篇关于当文件开始读取时发生的情况太大,无法使用“readlines()”读取所有行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!