import os.path
#过滤
in_file_object = open('d:\\1.txt')
out_file=open('D:\\2.txt','w')
for line in in_file_object:
if line.find('"')>0:
beg=line.find('"')
beg+=1
end=line.find('"',beg)
out_file.write(line[beg:end])
out_file.write('\n')
in_file_object.close( )
out_file.close()
#去重
lines_seen = set()
outfile = open("d:\\3.txt","w")
for line in open("d:\\2.txt","r"):
if line not in lines_seen:
outfile.write(line)
lines_seen.add(line)
outfile.close()
#排序
fp = open("d:\\3.txt","r+")
out=open("d:\\4.txt","w")
linesText = fp.readlines()
linesText.sort()
#for line in linesText:
#print(line);
out.writelines(linesText)
fp.close()
out.close()
python文件过滤,去重,排序
最新推荐文章于 2023-03-03 11:09:14 发布