how to print out each line of a text file python code example
Example 1: print file line by line python
with open('yourfile.txt','r') as f:
lines = f.readlines()
f.close()
Example 2: python read text file next line
filepath = 'Iliad.txt'
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
print("Line {}: {}".format(cnt, line.strip()))
line = fp.readline()
cnt += 1