Iterating over readlines() and map()

W. Martin Borgert debacle at debian.org
Wed Mar 25 21:02:04 EDT 2009


On 2009-03-26 01:41, Christian Heimes wrote:
> No, you are wrong. file.readlines() reads the entire file into memory
> and returns a list of strings. If you want to iterate over the lines of
> a text file you can simply write:
>
> for line in myfile:
>     dosomethingwith(line)
>
> It won't work for a binary file, though.

Thanks for the information! (In my case it's always text and not
even large, so reading in memory is OK. I just was curios.)



More information about the Python-list mailing list