def clear_space():
with open("test","r",encoding="utf-8") as fr:
for line in fr:
line = line.strip()
if len(line) > 0:
yield line
g = clear_space()
for line in g:
with open("test.bak","a",encoding="utf-8") as fw:
fw.write(line+"\n") ```
转载于:https://www.cnblogs.com/meilong/p/Python-qu-chu-wen-jian-zhong-de-kong-xing.html