Python - Read text files line by line

Description

Read text files line by line

Demo

for line in open('main.py').readlines(): 
    print(line.rstrip()) 

for line in open('main.py'):   # Use iterators: best for text input 
    print(line.rstrip())

Result

Related Example