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

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第三方库


热门话题
javajexcel包装文本问题   EclipseJavaEnum缩进超过左括号。如何让它看起来更正常?   java有办法包含Tomcat 6 catalina。out和localhost。在网络应用的日志文件中记录内容?   java如何永久性地阻止JavaFX代码在eclipse中被突出显示为错误?   如何在java中优化两个for循环(for循环中的for循环)   java如何在我的windows机器上从jar文件创建mac osx的可执行文件   使用记忆化/动态规划的Java组合学   Java中的游荡对象垃圾收集   java为什么我在JSP和JDBC和MySQL中遇到连接失败错误   java轮询Pod的就绪状态   如何创建电子邮件并将其发送到Java中的特定地址?   java如何修复Dagger 2错误“。。。无法提供[…]”?   java Android单选按钮看起来太轻   Android Studio:开发在应用程序之间共享的通用java库