python 文本去重

# -*- coding: utf8 -*-
#==============================
file_name = 'uk_urls.txt'
#==============================

open('quchong.txt','w').truncate()

with open(file_name, 'r') as f: 
    lines = f.readlines() 
print 'lines = ' + str(len(lines))

x = 0

while x < len(lines):

    file = open('quchong.txt', 'r')
    quchong = file.read()
    file.close()

    if lines[x] not in quchong:
        print '[' + str(x+1) + ']' + 'ok, add'
        file = open('quchong.txt', 'a')
        file.write(lines[x])
        file.close
    else:
        print '[' + str(x+1) + ']' + 'no, del:' + lines[x].replace('\n','')

    x= x + 1

猜你喜欢

转载自blog.csdn.net/kongjingrou/article/details/80747487
今日推荐