使用python读取txt文件的内容,并删除重复的行数方法
注意,本文代码是使用在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"
最终结果在在写入文件内容中,没有重复内容。
相关推荐
dflyzx 2020-09-17
higheels 2020-07-20
Ericbig 2020-07-19
yinyang00 2020-05-15
lijiuchangxin 2020-05-14
yogoma 2020-05-09
jacktangj 2020-04-19
Yyqingmofeige 2020-03-26
idning 2020-02-14
宿舍 2020-01-31
luenxin 2020-01-22
水痕 2020-01-18
chouliqingke 2020-01-08
secondid 2019-12-18
XCodeRush 2019-12-17
ryuhfxz 2019-11-20
qonsnow 2014-03-07
coulder 2019-11-17