国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python判斷兩個文件是否相同與兩個文本進行相同項篩選的方法

2020-02-16 01:26:37
字體:
來源:轉載
供稿:網友

python判斷兩個文件是否相同

import hashlibdef getHash(f):  line=f.readline()  hash=hashlib.md5()  while(line):    hash.update(line)    line=f.readline()  return hash.hexdigest()def IsHashEqual(f1,f2):  str1=getHash(f1)  str2=getHash(f2)  return str1==str2if __name__ == '__main__':  f1=open("D:/2.iso","rb")  f2=open("E:/wenjian/1.iso","rb")  print IsHashEqual(f1,f2)

計算2個文件的MD5值,大文件計算較慢

python對兩個文本進行相同項篩選

import osimport os.path as ospdef filter(path):  file_path = osp.join(path, 'index.txt')  if osp.exists(file_path):    return file_path  index_file = open(file_path, 'a+')  if not os.path.isdir(path):  #判斷path是否為路徑     return    for root, dirs, list in os.walk(path):    for i in list:       dir = os.path.join(root, i)  #將分離的部分組成一個路徑名       #if os.path.getsize(dir) < 60000:  #獲取文件大小         #os.remove(dir)       #刪除文件       print (i)      index_file.write(i+'/n')  index_file.close()    def compare(path):  file=osp.join(path, 'label.txt')  file_path = osp.join(path, 'index.txt')  with open(file_path, 'r') as file1:     with open(file, 'r') as file2:       same = set(file1).intersection(file2)  same.discard('/n')  with open('some_output_file.txt', 'w') as file_out:     for line in same:       file_out.write(line)  file_out.close()filter(r'D:/Desktop/jiaoben/ci')compare(r'D:/Desktop/jiaoben/ci')

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林站長站的支持。如果你想了解更多相關內容請查看下面相關鏈接

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天柱县| 修文县| 松原市| 手游| 大新县| 交城县| 东丰县| 桃园市| 监利县| 德安县| 思南县| 贺兰县| 额尔古纳市| 镇康县| 达尔| 南乐县| 婺源县| 通化县| 峨眉山市| 重庆市| 江津市| 普洱| 安仁县| 双辽市| 旌德县| 临澧县| 肥城市| 景洪市| 佛山市| 东阿县| 瑞安市| 正镶白旗| 马鞍山市| 娄烦县| 竹北市| 怀仁县| 潼南县| 磴口县| 洪洞县| 湄潭县| 班戈县|