Nov-17-2017, 04:34 AM
readline is the least used. You would only use it in the event the file was too large that readlines() is too much to put into RAM or too slow to do so. And then you would most likely use a database instead. You can also control how many bytes are read if you give it an argument.
You wouldnt use readline in a for loop. Something like this
You wouldnt use readline in a for loop. Something like this
f = open('text.txt') line = f.readline() while line: print(line, end='') line = f.readline()where readlines would be
with open('text.txt') as f: lines = f.readlines()Even if you wanted to read the first 5 lines of a file would would just splice readlines()
Recommended Tutorials: