Iterating over readlines() and map()

W. Martin Borgert debacle at
Thu Mar 26 02:02:04 CET 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