Iterating over readlines() and map()

W

W. Martin Borgert

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top