Python 3 Script to Remove Blank or Empty Lines From Text File Full Project For Beginners

Python 3 Script to Remove Blank or Empty Lines From Text File Full Project For Beginners

 

Welcome folks today in this blog post we will be removing blank lines inside text file using python. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

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)

 

 

Here in this python script we are taking the input text file which contains empty or blank lines and then we are removing the empty lines and storing the result into a separate text file as shown below

See also  Python 3 (OpenCV + Numpy) Script to Extract Dominant Color in RGB Hex Code From Image File Full Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py

 

 

Leave a Reply