Python: how can i read a file line by line?

Example:

with open('filename.txt', 'r') as file:
    for line in file:
        print(line)
Use a `with` statement to open the file and then iterate over the file object to read it line by line.

Beginner's Guide to Python