1. 程式人生 > 其它 >python讀檔案去除空行後寫入新檔案

python讀檔案去除空行後寫入新檔案

技術標籤:python

with open("D:\work\pui.txt",'r') as fr,open("D:\work\ew.txt",'w',encoding = 'utf-8') as fd:
    for text in fr.readlines():
        if text.split():
            fd.write(text)