Answers for "removing extra empty lines in python"

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

how to remove blank lines from string in python

re.sub(r'^$n', '', s, flags=re.MULTILINE)
Posted by: Guest on June-15-2021

Code answers related to "removing extra empty lines in python"

Python Answers by Framework

Browse Popular Code Answers by Language