Because for line in x iterates through each line.
with open('test.txt') as x: for line in x:
Did you mean:
with open('test.txt') as x: print(x.read())
to print all at once, or:
with open('test.txt') as x: for line in x: print line.rstrip()
for printing line by line. The latter is recommended, since you do not need to immediately load the entire contents of the file into memory.
source share