我有许多文件,我正在运行多个正则表达式匹配,并删除内容。它工作正常,但是每当有匹配时,我都会在底部得到重复的行,我每次都手动删除这些行。这是怎么回事?
for year in range (2004,2009):
path="/foo/bar/"+str(year)+"/"
dirs = os.listdir(path)
for i in range(0,len(dirs)):
original_file = os.path.join(path, dirs[i])
f=open(original_file,"r+")
text=f.read()
text=re.sub('FY91/92','',text)
f.seek(0)
f.write(text)
f.close()