python文件过滤,去重,排序

来源:互联网 发布:如何拆分单元格数据 编辑:程序博客网 时间:2024/05/22 13:23
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()


原创粉丝点击