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

Xiao Jianfeng fdu.xiaojf at gmail.com
Sat Nov 19 22:05:53 EST 2005


bonono at gmail.com wrote:

>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.
>
>  
>
 I have some other questions:

 when "fh" will be closed?

 And what shoud I do if I want to explicitly close the file immediately 
after reading all data I want?

>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