while loop with f.readline()

David Bolen db3l at fitlinxx.com
Wed Feb 14 14:18:03 EST 2001


Phlip <phlip_cpp at my-deja.com> writes:

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

Nothing "wrong" - but realize that doing it that way will read the
entire file into memory (into the list object returned by readlines())
and then iterate over that object.

Probably not be the best idea if you're looking at large files, but
certainly doable for small to middling stuff.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list