what happens when the file begin read is too big for all lines to be read with "readlines()"

bonono at gmail.com bonono at gmail.com
Sat Nov 19 06:22:51 EST 2005


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 -
> 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.




More information about the Python-list mailing list