Is it better to read an entire file before performing operations or is it better to perform operations while reading from the file?
If I was reading the entire file first, I'd store the information line-by-line in a list and if I was reading the file and operating on the data at the same time, I would be reading line-by-line and executing my operation after a line is read.
For the sake of the discussion, let's say the file isn't obscenely large. It would be nice to hear thoughts on small files and large files and if actions would differ. Also, I presume the operations also play a role; I'm reading URL's and downloading files.
with open(filename) as file: data=file.read().split("\n"). Just because I don't like putting large pieces of code inwithblocks, nor do I want to remember toclosefiles long after I've opened them. But that's just, like, my opinion, man.for line in freadlines()then iterating over seems just slightly slower than just iterating over the file object in a file that has 100 lines.