I read that it file.readlinesreads the entire file line by line and saves it in a list. If I have a file like so -
Sentence 1
Sentence 2
Sentence 3
and I use readlinesto print each sentence like this -
file = open("test.txt")
for i in file.readlines():
print i
Exit
Sentence 1
Sentence 2
Sentence 3
My question is: why do I get an extra line between each sentence and how can I get rid of it?
UPDATE
I found that using i.stripalso removes extra lines. Why is this happening? As far as I know, splitremoves spaces at the end and beginning of a line.
source
share