Read text files line by line
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())