使用python读取txt文件的内容,并删除重复的行数方法
时间:2020-12-14 14:16:43|栏目:Python代码|点击: 次
注意,本文代码是使用在txt文档上,同时txt文档中的内容每一行代表的是图片的名字。
#coding:utf-8
import shutil
readDir = "原文件绝对路经"
writeDir = "写入文件的绝对路径"
#txtDir = "/home/fuxueping/Desktop/1"
lines_seen = set()
outfile=open(writeDir,"w")
f = open(readDir,"r")
for line in f:
if line not in lines_seen:
outfile.write(line)
lines_seen.add(line)
outfile.close()
print "success"
最终结果在在写入文件内容中,没有重复内容。






