我有以下脚本,它根据数组识别要删除的文件中的行,但不会删除它们。Python脚本从数组中包含文字的文件中删除行
我应该改变什么?
sourcefile = "C:\\Python25\\PC_New.txt"
filename2 = "C:\\Python25\\PC_reduced.txt"
offending = ["Exception","Integer","RuntimeException"]
def fixup(filename):
print "fixup ", filename
fin = open(filename)
fout = open(filename2 , "w")
for line in fin.readlines():
for item in offending:
print "got one",line
line = line.replace(item, "MUST DELETE")
line=line.strip()
fout.write(line)
fin.close()
fout.close()
fixup(sourcefile)
我不认为你打印过任何东西。 – Daenyth 2010-06-15 06:08:47
@Daenyth - 修改该行。它在o/p文件中打印出每行三行 – romesub 2010-06-15 06:11:37