`readlines()` reads the remaining lines from an open file object and returns a list of strings, one per line. Trailing newline characters remain in the strings. Use it when you need the lines together, for example to count them with `len(lines)`. section 13.4
""" Reads a file and returns the number of lines, words,
and characters - similar to the UNIX wc utility
"""
with open('word_count.tst') as infile:
lines = infile.readlines() #1
line_count = len(lines)
word_count = sum(len(line.split()) for line in lines) #2
char_count = sum(len(line) for line in lines) #3
print(f"{line_count} lines, {word_count} words, {char_count} characters")
This word counter reads the file once, then uses the list of lines to count lines, words, and characters. Because the newline characters remain in each line, `len(line)` includes them. section 8.13.2
Reading every line at once can use too much memory for a very large file. If you only need to process lines one at a time, iterate over the file object instead. `readline()` reads a single line; both `readline()` and `readlines()` also accept an optional argument affecting how much they read, with details in the Python reference documentation. section 13.4
Do not assume `infile.read().split("\n")` is interchangeable with `infile.readlines()` for character counts: splitting removes the separator characters, so summing the lengths of the resulting strings misses newlines. For text files whose original line endings must survive a read-and-write cycle, open with `newline=""` before calling `readlines()` and writing the strings with `writelines()`. section 8.13.2 section 13.4
The method also belongs to `sys.stdin`, which can be treated as a specialized file object when input is redirected. section 13.6

