I have read that file.readlines
reads the whole file line by line and stores it in a list.
If I have a file like so -
Sentence 1
Sentence 2
Sentence 3
and I use readlines
to print each sentence like so -
file = open("test.txt")
for i in file.readlines():
print i
The output is
Sentence 1
Sentence 2
Sentence 3
My question is why do I get the extra line between each sentence and how can I get rid of it?
UPDATE
I found that using i.strip
also removes the extra lines. Why does this happen? As far as I know, split
removes the white spaces at the end and beginning of a string.