【发布时间】:2018-05-04 05:32:13
【问题描述】:
我的输入文件“input.dat”包含一些像这样的值:
41611 2014 12 18 0 0
41615 2014 12 18 0 0
41625 2014 12 18 0 0
41640 2014 6 14 3 3
42248 2014 12 18 0 0
42323 2014 12 18 0 0
42330 2014 8 13 7 7
42334 2014 12 18 0 0
42335 2014 12 18 0 0
...
我有很多数据集文件,但似乎有很多不需要的数据 如何立即删除这种情况下的多行 41640 和 42330 及其整个行值。现在我使用了这个脚本:
with open(path+fname,"r") as input:
with open("00-new.dat","wb") as output:
for line in input:
if line!="41640"+"\n":
output.write(line)
结果:输出中仍然存在数据 41640。有什么想法吗??
【问题讨论】:
标签: python-2.7 file-handling delete-row