python read text file without newline code example
Example 1: python read file without newline
# converts read file into a list without newlines
temp = file.read().splitlines()
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