您可以遍历检查字词,并使用
zip替换到替换词。
例如:
checkWords = ("old_text1","old_text2","old_text3","old_text4")repWords = ("new_text1","new_text2","new_text3","new_text4")for line in f1: for check, rep in zip(checkWords, repWords): line = line.replace(check, rep) f2.write(line)f1.close()f2.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)