词典、词典、字符串和其他对象的巨大差异。它将递归地查找所有更改。

pivotal-deepdiff的Python项目详细描述


深度差V 0.6.1

DownloadsPython VersionsLicense

词典、词典、字符串和其他对象的巨大差异。它将递归地查找所有更改。 在Python2.7和3.4上测试

注意:

this fork提供了专门处理浮点相关字段中舍入的更改

安装

从pypi安装:

pip install deepdiff

导入

>>>fromdeepdiffimportDeepDiff

支持的数据类型

int,string,dictionary,list,tuple,set,frozenset,ordereddict,namedtuple和自定义对象!

示例

同一对象返回空值

>>>t1={1:1,2:2,3:3}>>>t2=t1>>>ddiff=DeepDiff(t1,t2)>>>ddiff{}

项目类型已更改

>>>t1={1:1,2:2,3:3}>>>t2={1:1,2:"2",3:3}>>>ddiff=DeepDiff(t1,t2)>>>print(ddiff){'type_changes':["root[2]: 2=<type 'int'> ===> 2=<type 'str'>"]}

项目值已更改

>>>t1={1:1,2:2,3:3}>>>t2={1:1,2:4,3:3}>>>ddiff=DeepDiff(t1,t2)>>>print(ddiff){'values_changed':['root[2]: 2 ===> 4']}

添加和/或删除的项目

>>>t1={1:1,2:2,3:3,4:4}>>>t2={1:1,2:4,3:3,5:5,6:6}>>>ddiff=DeepDiff(t1,t2)>>>pprint(ddiff){'dic_item_added':['root[5, 6]'],'dic_item_removed':['root[4]'],'values_changed':['root[2]: 2 ===> 4']}

字符串差异

>>>t1={1:1,2:2,3:3,4:{"a":"hello","b":"world"}}>>>t2={1:1,2:4,3:3,4:{"a":"hello","b":"world!"}}>>>ddiff=DeepDiff(t1,t2)>>>frompprintimportpprint>>>pprint(ddiff,indent=2){'values_changed':['root[2]: 2 ===> 4',"root[4]['b']: 'world' ===> 'world!'"]}>>>>>>print(ddiff['values_changed'][1])root[4]['b']:'world'===>'world!'

字符串差异2

>>>t1={1:1,2:2,3:3,4:{"a":"hello","b":"world!\nGoodbye!\n1\n2\nEnd"}}>>>t2={1:1,2:2,3:3,4:{"a":"hello","b":"world\n1\n2\nEnd"}}>>>ddiff=DeepDiff(t1,t2)>>>pprint(ddiff,indent=2){'values_changed':["root[4]['b']:\n"'--- \n''+++ \n''@@ -1,5 +1,4 @@\n''-world!\n''-Goodbye!\n''+world\n'' 1\n'' 2\n'' End']}>>>>>>print(ddiff['values_changed'][0])root[4]['b']:---+++@@-1,5+1,4@@-world!-Goodbye!+world12End

类型更改

>>>t1={1:1,2:2,3:3,4:{"a":"hello","b":[1,2,3]}}>>>t2={1:1,2:2,3:3,4:{"a":"hello","b":"world\n\n\nEnd"}}>>>ddiff=DeepDiff(t1,t2)>>>pprint(ddiff,indent=2){'type_changes':["root[4]['b']: [1, 2, 3]=<type 'list'> ===> world\n"'\n''\n'"End=<type 'str'>"]}

列表差异

>>>t1={1:1,2:2,3:3,4:{"a":"hello","b":[1,2,3]}}>>>t2={1:1,2:2,3:3,4:{"a":"hello","b":[1,2]}}>>>ddiff=DeepDiff(t1,t2)>>>pprint(ddiff,indent=2){'iterable_item_removed':["root[4]['b']: [3]"]}

列表差异2

>>>t1={1:1,2:2,3:3,4:{"a":"hello","b":[1,2,3]}}>>>t2={1:1,2:2,3:3,4:{"a":"hello","b":[1,3,2,3]}}>>>ddiff=DeepDiff(t1,t2)>>>pprint(ddiff,indent=2){'iterable_item_added':["root[4]['b']: [3]"],'values_changed':["root[4]['b'][1]: 2 ===> 3","root[4]['b'][2]: 3 ===> 2"]}

包含字典的列表:

>>>t1={1:1,2:2,3:3,4:{"a":"hello","b":[1,2,{1:1,2:2}]}}>>>t2={1:1,2:2,3:3,4:{"a":"hello","b":[1,2,{1:3}]}}>>>ddiff=DeepDiff(t1,t2)>>>pprint(ddiff,indent=2){'dic_item_removed':["root[4]['b'][2][2]"],'values_changed':["root[4]['b'][2][1]: 1 ===> 3"]}

设置

>>>t1={1,2,8}>>>t2={1,2,3,5}>>>ddiff=DeepDiff(t1,t2)>>>print(DeepDiff(t1,t2)){'set_item_added':['root: [3, 5]'],'set_item_removed':['root: [8]']}

命名元组:

>>>fromcollectionsimportnamedtuple>>>Point=namedtuple('Point',['x','y'])>>>t1=Point(x=11,y=22)>>>t2=Point(x=11,y=23)>>>print(DeepDiff(t1,t2)){'values_changed':['root.y: 22 ===> 23']}

自定义对象:

>>>classClassA(object):...a=1...def__init__(self,b):...self.b=b...>>>t1=ClassA(1)>>>t2=ClassA(2)>>>>>>print(DeepDiff(t1,t2)){'values_changed':['root.b: 1 ===> 2']}

添加的对象属性:

>>>t2.c="new attribute">>>print(DeepDiff(t1,t2)){'attribute_added':['root.c'],'values_changed':['root.b: 1 ===> 2']}

忽略顺序:

注意:如果您的对象包含包含任何不可更改项的iterable,忽略该顺序可能会很昂贵。

>>>t1=[{"a":2},{"b":[3,4,{1:1}]}]>>>t2=[{"b":[3,4,{1:1}]},{"a":2}]ddiff=DeepDiff(t1,t2,ignore_order=True)>>>>>>print(DeepDiff(t1,t2)){}

文档

http://deepdiff.readthedocs.org/en/latest/

构建过程:

  1. 更新应用程序内部的__version_info__。承诺和推动。
  2. 用版本标记发布。git tag <version> -m "Release"; git push --tags
  3. 构建版本rm -rf dist build *egg-info; python setup.py sdist bdist_wheel
  4. 上传数据twine upload dist/*

更改日志

原作者

塞伯曼 Github:https://github.com/seperman LinkedIn:http://www.linkedin.com/in/sepehr 玉米加工厂:http://www.zepworks.com

感谢: 初始py3移植的brbsix 支持Unicode的Wangfenjin

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用“Wed,01 Jul 2015 17:32:41 EDT”解析字符串   java Storm apache升级(1.0.0到2.0.0)   java类驻留在不同的目录中,而不是包指定的目录。为什么?   将Java中的图像缩放到非常小的维度   java如何通过子文档从自定义方面访问ElasticSearch parentdoc字段   java如何在RationalSoftwareArchitect中使用findbugs?   Java中的事件提升处理   java值被添加到arrayList的所有索引中,而不是在“”时添加到最后一个索引中。正在使用arraylist的add()方法   JFrame中的java JPanel派生类   java如何用循环和异步方法模拟类   java Android阻止可绘制背景超出视图范围   为客户排序Java阵列   java Apache poi如何将工作表设置为枚举位置值属性?   java Rhino在使用自定义类参数调用javascript函数时出错   java格式化日期从年月日到年月日   spring如何修复java。lang.illegalargumentexception在此特定场景中是否尝试创建具有null实体的合并事件?   java如何创建更好的对象