Iterating over readlines() and map()

W. Martin Borgert debacle at debian.org
Wed Mar 25 20:27:14 EDT 2009


(Resend, because of funny error message:
> Your mail to 'Python-list' with the subject
>     Iterating over readlines() and map()
> Is being held until the list moderator can review it for approval.
Whatever this means.)

Hi,

if I understand correctly, this code would not read the complete file
into the memory:

for line in myfile.readlines():
    dosomethingwith(line)

Is this also true for this code?

for line in map(myfunction, myfile.readlines()):
    dosomethingwith(line)

Or would use of map() mean, that the complete "myfile" is read into
the RAM? In this case, I would change it to:

for line in myfile.readlines():
    line = myfunction(line)
    dosomethingwith(line)

TIA!



More information about the Python-list mailing list