python 快速文件对比

import os,sys,time,json,time
import socket,random,hashlib
import requests,configparser
import json
from datetime import datetime
from multiprocessing.dummy import Pool as ThreadPool

arr={};

def read1(filepath, val):
    with open(filepath) as f:
        for line in f:
            tmp = line.replace('\r','');
            tmp = tmp.replace('\n','');
            if(len(tmp)==0):
                continue
            arr[tmp] = val


def SaveLog(filepath, text, isNewfile=False):
    if(isNewfile==True and os.path.isfile(filepath) and os.path.exists(filepath)):
        os.remove(filepath)
    with open(filepath,'a') as f:
        f.write(text)


def output1(filepath):
    outfile1 = sys.argv[1] + ".out.txt"
    outfile2 = sys.argv[2] + ".out_共有部分.txt"
    if(os.path.exists(outfile1)):
        os.remove(outfile1)
    if(os.path.exists(outfile2)):
        os.remove(outfile2)
    for key in arr:
        if(arr[key]==0):
            SaveLog(outfile1,key + "\r\n")
            print(key + "=0")
        else:
            SaveLog(outfile2,key+ "\t共有部分\r\n")
            print(key + "=1 共有部分")

def main():
    if (len(sys.argv)<3):
        print("me.py a.txt b.txt")
    else:
        file1 = sys.argv[1]
        if(False==os.path.exists(file1)):
            file1 = "a.txt"
        file2 = sys.argv[2]
        if(False==os.path.exists(file2)):
            file2= "b.txt"
        print("*" * 60)
        read1(file1, 0)
        read1(file2, 1)
        output1('c.txt');
        print("*" * 60)

 

 

if __name__ == '__main__':
    main()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值