黑松山资源网 Design By www.paidiu.com
python判断两个文件是否相同
import hashlib def 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==str2 if __name__ == '__main__': f1=open("D:/2.iso","rb") f2=open("E:/wenjian/1.iso","rb") print IsHashEqual(f1,f2)
计算2个文件的MD5值,大文件计算较慢
python对两个文本进行相同项筛选
import os import os.path as osp def 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')
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月07日
2024年10月07日
- 班得瑞原装进口《第五张新世纪专辑:迷雾森林+EP》1CD[APE/CUE分轨][334.2MB]
- 田震.1997-顺其自然(日版)【红星生产社】【WAV+CUE】
- 小虫.1996-想得太美【滚石】【WAV+CUE】
- 谢采妘.2016-邓丽君名曲专辑【丰荣】【WAV+CUE】
- 张含韵.2007-一人一梦【天中文化】【WAV+CUE】
- 蟑螂乐队.1999-帮个忙【福茂】【WAV+CUE】
- 张宇.2001-替身【EMI百代】【WAV+CUE】
- 班得瑞原装进口《第六张新世纪专辑:日光海岸》1CD[APE/CUE分轨][339.5MB]
- 班得瑞原装进口《第七张新世纪专辑:梦花园》1CD[APE/CUE分轨][331.4MB]
- 班得瑞原装进口《第八张新世纪专辑:琉璃湖畔》1CD[APE/CUE分轨][286.4MB]
- 魏如萱.2011-在哪里(EP)【添翼创越】【WAV+CUE】
- 群星.1981-新金曲奖·青年创作园地12合辑(喜玛拉雅复刻版)【歌林】【WAV+CUE】
- 麦洁文.1989-新曲与精丫新艺宝】【WAV+CUE】
- SNH48《薄荷糖 (Mint Candy)》[320K/MP3][33.72MB]
- SNH48《薄荷糖 (Mint Candy)》[FLAC/分轨][78.59MB]