Iterating over readlines() and map()

W. Martin Borgert debacle at debian.org
Wed Mar 25 16:16:26 EDT 2009


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