Answers for "remove empty lines from text file"

0

remove empty lines from file python

with open("new_file","r") as f:
 for i in f.readlines():
       if not i.strip():
           continue
       if i:
           print i,
Posted by: Guest on November-05-2020
0

python remove empty lines from file

import os


def remove_empty_lines(filename):
    if not os.path.isfile(filename):
        print("{} does not exist ".format(filename))
        return
    with open(filename) as filehandle:
        lines = filehandle.readlines()

    with open(filename, 'w') as filehandle:
        lines = filter(lambda x: x.strip(), lines)
        filehandle.writelines(lines)
Posted by: Guest on June-29-2021
0

remove lines from textfile

var lines = System.IO.File.ReadAllLines("...");
System.IO.File.WriteAllLines("...", lines.Take(lines.Length - 1).ToArray());
Posted by: Guest on September-09-2021

Code answers related to "remove empty lines from text file"

Python Answers by Framework

Browse Popular Code Answers by Language