I got downvoted for an answer using file.readlines. The critic said that using readlines is crap code (along with other very rude statements).
Is it so bad?
I assume that the problem was the fact that readlines()
loads the whole file into memory, which - theoretically - can be a lot.
A lazy approach (iterating over the file and reading progressively as needed) is indeed better in terms of memory usage. Not sure about efficiency, though.
No, readlines
is fine. You just have to remember, that the whole file is stored in memory at one point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With