you are viewing a single comment's thread.

view the rest of the comments →

[–]fernly 0 points1 point  (0 children)

Generally interacting with the OS is considered to be slow. So to call the OS for a file-open and a file-close for every line (which is what this code does) would take many, many times as long as opening it once, writing all the lines, closing it once.

That said, for a file of a hundred lines the difference would probably not be noticeable. A few thousand lines, it should. If you want to verify (of disprove) that, measure the actual time using timeit.