1、 比较2个文件是否一致,并且渲染出不一致的地方
import difflib
def readfile(filename):
with open(filename, 'r',encoding='utf-8') as f
text = f.readlines()
return text
if __name__ == '__main__':
d = difflib.HtmlDiff()
fromlines = readfile('test1')
tolines= readfile('test2')
res = d.make_file(fromlines,tolines)
with open('report.html', 'w+') as f:
f.write(res)
2、比较文件内容是否一致
import hashlib
import requests
def req(url):
with open('test.txt','rb) as f :
content = f.read()
return hashlib.md5(content).hexdigest()
if __name__ == '__main__':
fromlines = readfile('test1')
tolines= readfile('test2')
if tolines == fromlines:
print('文件内容一致')
else:
print('文件内容不一致')
文章知识点与官方知识档案匹配,可进一步学习相关知识