nick34992 of Python
2/2/2017 - 7:13 AM

Python Iterate through Multi-Line Text File #python

Python Iterate through Multi-Line Text File #python

Think, my lord!
By heaven, he echoes me,
As if there were some monster in his thought
Too hideous to be shown. Thou dost mean something:
I heard thee say even now, thou likedst not that,
When Cassio left my wife: what didst not like?
And when I told thee he was of my counsel
In my whole course of wooing, thou criedst 'Indeed!'
And didst contract and purse thy brow together,
As if thou then hadst shut up in thy brain
Some horrible conceit: if thou dost love me,
Show me thy thought.
#!/usr/bin/env python3
# may need to use full path to file

filename = 'othello.txt'

file = open(filename, "r")
first_line = file.readline().strip()

while first_line != "":
    second_line = file.readline().strip()
    third_line = file.readline().strip()
    print(first_line, second_line, third_line)
    first_line = file.readline().strip()