Python 3 Script to Remove Blank or Empty Lines From Text File

Python 3 Script to Remove Blank or Empty Lines From Text File

Python 3 Script to Remove Blank or Empty Lines From Text File

import sys
output=""
with open("file.txt") as f:
    for line in f:
        if not line.isspace():
            output+=line
            
f= open("output.txt","w")
f.write(output)
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment