简介
主要用来对比两个对象之间的差异性,搜索某个元素是都在一个对象中,对一个可迭代对象进行hash运算。
应用场景
自动化脚本测试
安装
pip install deepdiff==4.3.2
Python 3.7.6
pip 20.1.1
主要组成部分
DeepDiff:比较两个对象,对象可以是字段、字符串等可迭代的对象
DeepSearch:在对象中搜索其他对象
DeepHash:根据对象的内容进行哈希处理
DeepDiff使用
文本文件对比
from deepdiff import DeepDiff
class Diff():
def file_compare(self):
'''文件内容对比
'''
with open("a.log", 'r', encoding='utf-8') as file:
file_a = file.read()
with open("b.log", "r", encoding='utf-8') as file:
file_b = file.read()
rs = DeepDiff(file_a, file_b)
print(rs)
if __name__ == "__main__":
di = Diff()
di.file_compare()
#测