【发布时间】:2021-05-27 08:58:44
【问题描述】:
我试图弄清楚如何在仅使用 python 时从文本文件中删除一个空行。 输入应该是这样的:
firstline
secondline
thirdline
输出应该是:
firstline
secondline
thirdline
所以我现在有这个......
import sys
with open("New Text Document.txt") as f:
for line in f:
if not line.isspace():
sys.stdout.write(line)
【问题讨论】:
-
这不是“为我做”董事会朋友。
-
欢迎来到 SO。请看(如何提出好问题)[stackoverflow.com/help/how-to-ask]
-
你的代码已经给出了你想要的输出。