0

I'm trying to figure out how to remove an empty line from a text file while only using python. The input should be like:

firstline
secondline

thirdline

And the output should be:

firstline
secondline
thirdline

So I have this right now...

import sys

with open("New Text Document.txt") as f:
    for line in f:
        if not line.isspace():
            sys.stdout.write(line)
pearlwrap
  • 3
  • 5

1 Answers1

0
file = open('demo.txt', 'r')
arr = file.readlines()
print([v for v in arr if not v.isspace()])
meadhu
  • 11
  • 1