This might be a simple question but I just started Python and don't know why this is not working. I am trying to remove the empty lines from a text and nothing seems to work.
I have the following sample text
The Project Gutenberg EBook of Alice in Wonderland, by Lewis Carroll
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.org
Title: Alice in Wonderland
Author: Lewis Carroll
Illustrator: Gordon Robinson
Release Date: August 12, 2006 [EBook #19033]
Language: English
Character set encoding: ASCII
*** START OF THIS PROJECT GUTENBERG EBOOK ALICE IN WONDERLAND ***
and I need the outcome to be a long line of text like so:
The Project Gutenberg EBook of Alice in Wonderland, by Lewis Carroll This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org Title: Alice in Wonderland Author: Lewis Carroll Illustrator: Gordon Robinson Release Date: August 12, 2006 [EBook #19033] Language: English Character set encoding: ASCII *** START OF THIS PROJECT GUTENBERG EBOOK ALICE IN WONDERLAND ***
I have tried
text=open("sample.txt","r")
for line in text:
line = line.rstrip()
print(line)
and .strip() as well but they don't do anything to the text. Is there a reason this does not work? I would like the code to be a one liner or something I can save as a variable because I need the outcome later. This is part of a larger project and I can't get past this.