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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top