日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python判断相同,Python判断两个文件是否相同与两个文本进行相同项筛选的方法

發布時間:2023/12/3 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python判断相同,Python判断两个文件是否相同与两个文本进行相同项筛选的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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')

總結

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

如您對本文有疑問或者有任何想說的,請點擊進行留言回復,萬千網友為您解惑!

總結

以上是生活随笔為你收集整理的python判断相同,Python判断两个文件是否相同与两个文本进行相同项筛选的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。