当文件开始读取时发生的情况太大,无法使用“readlines()”读取所有行。 [英] what happens when the file begin read is too big for all lines to beread with "readlines()"

查看:463
本文介绍了当文件开始读取时发生的情况太大,无法使用“readlines()”读取所有行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

较新的python应该使用for f in fh:,根据文档:


fh = open(" your文件")
$ f $ b for x in fh:print x


,一次只读一行。


Ross Reyes写道:
newer python should use "for x in fh:", according to the doc :

fh = open("your file")
for x in fh: print x

which would only read one line at a time.

Ross Reyes wrote:
HI -
抱歉也许是一个太简单的问题,但我用Google搜索并检查了我的
参考O''Reilly学习Python
书和我没有找到一个满意的答案。

当我使用readlines时,如果n线条很大?我有一个非常大的文件(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.






更新的python应该使用for f in fh: ,根据文件:


fh =打开(你的文件)

for x in fh:print x


,一次只读一行。


Ross Reyes写道:
newer python should use "for x in fh:", according to the doc :

fh = open("your file")
for x in fh: print x

which would only read one line at a time.

Ross Reyes wrote:
HI -
对不起也许也是简单的一个问题,但我谷歌搜索并检查了我的参考O'Reilly学习Python
书,我没有找到一个满意的答案。

当我使用readlines时,会发生什么如果行数很大?我有一个非常大的文件(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.






Ross Reyes< ro ******* @ rcn.com>写道:
Ross Reyes <ro*******@rcn.com> wrote:
对不起,也许是一个太简单的问题,但我用Google搜索并检查了我的参考O''Reilly学习Python书,我没有找到一个满意的答案。


Python文档在线,熟悉

它很好:


< URL:http://docs.python.org/>


甚至可以告诉Google只搜索该网站

" site:docs.python.org"作为一个搜索词。

当我使用readlines时,如果行数很大会怎么样?
我有一个非常大的文件(4GB)我想读,但我'我确定
必须对readlines有一些限制,我想知道它是如何由python处理的。
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.
The Python documentation is online, and it''s good to get familiar with
it:

<URL:http://docs.python.org/>

It''s even possible to tell Google to search only that site with
"site:docs.python.org" as a search term.
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.




关于''文件''类型方法的文档描述了

''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()”读取所有行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆