while loop with f.readline()

Jeff Epler jepler at inetnebr.com
Wed Feb 14 09:17:22 EST 2001


On 14 Feb 2001 05:15:14 GMT, Phlip
 <phlip_cpp at my-deja.com> wrote:
>Came to the thread late can't read all posts don't know if this was covered 
>so sue me but...
>
>...what's wrong with this?
>
>        for z in f.readlines():
>                print z
>
>That's how I done it since I was a chile'. 

If the contents of f are larger than memory, this won't work.  If the
contents of f are large compared to memory, then it won't work very well.

This is one reason that 2.1 will include "xreadlines", which will work
just like the above:
        for z in f.xreadlines():
                print z
but will never hold the entire file in memory.

Jeff



More information about the Python-list mailing list