“Usuń puste linie z pliku Python” Kod odpowiedzi

Usuń puste linie z pliku Python

with open("new_file","r") as f:
 for i in f.readlines():
       if not i.strip():
           continue
       if i:
           print i,
Dead Dog

Python Usuń puste linie z pliku

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)   
aso

Odpowiedzi podobne do “Usuń puste linie z pliku Python”

Pytania podobne do “Usuń puste linie z pliku Python”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu