shutil文件去重模块

使用文档

# -*- coding:utf-8 -*-
#! python2
import shutil
a=0
readDir = r"D:\pycharm-project\my-project\test\thefile2018-11-27.sh"
writeDir = r"D:\pycharm-project\my-project\test\new.txt"
# txtDir = "/home/Administrator/Desktop/1"
lines_seen = set()
outfile = open(writeDir, "w")
f = open(readDir, "r")
for line in f:
    if line not in lines_seen:
        a+= 1
        outfile.write(line)
        lines_seen.add(line)
        print(a)
        print('\n')
 
outfile.close()
print("success")
posted @ 2020-07-28 11:17  名字很长容易被惦记  阅读(113)  评论(0编辑  收藏  举报