@@ -105,17 +105,11 @@ def __getitem__(self, old_key):
105
105
class DeepDiff (RemapDict ):
106
106
107
107
r"""
108
- **DeepDiff v 1.7.0 **
108
+ **DeepDiff**
109
109
110
110
Deep Difference of dictionaries, iterables, strings and almost any other object.
111
111
It will recursively look for all the changes.
112
112
113
- **Pycon 2016 Talk**
114
- I gave a talk about how DeepDiff does what it does at Pycon 2016.
115
- `Diff it to Dig it Pycon 2016 video <https://www.youtube.com/watch?v=J5r99eJIxF4>`_
116
-
117
- And here is more info: http://zepworks.com/blog/diff-it-to-digg-it/
118
-
119
113
**Parameters**
120
114
121
115
t1 : A dictionary, list, string or any python object that has __dict__ or __slots__
@@ -157,6 +151,12 @@ class DeepDiff(RemapDict):
157
151
158
152
int, string, unicode, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple and custom objects!
159
153
154
+ **Pycon 2016 Talk**
155
+ I gave a talk about how DeepDiff does what it does at Pycon 2016.
156
+ `Diff it to Dig it Pycon 2016 video <https://www.youtube.com/watch?v=J5r99eJIxF4>`_
157
+
158
+ And here is more info: http://zepworks.com/blog/diff-it-to-digg-it/
159
+
160
160
**Examples**
161
161
162
162
Importing
@@ -182,17 +182,24 @@ class DeepDiff(RemapDict):
182
182
Value of an item has changed
183
183
>>> t1 = {1:1, 2:2, 3:3}
184
184
>>> t2 = {1:1, 2:4, 3:3}
185
- >>> pprint(DeepDiff(t1, t2), indent=2)
185
+ >>> pprint(DeepDiff(t1, t2, verbose_level=0 ), indent=2)
186
186
{'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
187
187
188
188
Item added and/or removed
189
- >>> t1 = {1:1, 2:2, 3:3, 4:4}
190
- >>> t2 = {1:1, 2:4, 3:3, 5:5, 6:6}
189
+ >>> t1 = {1:1, 3:3, 4:4}
190
+ >>> t2 = {1:1, 3:3, 5:5, 6:6}
191
191
>>> ddiff = DeepDiff(t1, t2)
192
192
>>> pprint (ddiff)
193
193
{'dictionary_item_added': {'root[5]', 'root[6]'},
194
- 'dictionary_item_removed': {'root[4]'},
195
- 'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
194
+ 'dictionary_item_removed': {'root[4]'}}
195
+
196
+ Set verbose level to 2 in order to see the added or removed items with their values
197
+ >>> t1 = {1:1, 3:3, 4:4}
198
+ >>> t2 = {1:1, 3:3, 5:5, 6:6}
199
+ >>> ddiff = DeepDiff(t1, t2, verbose_level=2)
200
+ >>> pprint(ddiff, indent=2)
201
+ { 'dictionary_item_added': {'root[5]': 5, 'root[6]': 6},
202
+ 'dictionary_item_removed': {'root[4]': 4}}
196
203
197
204
String difference
198
205
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":"world"}}
@@ -247,6 +254,13 @@ class DeepDiff(RemapDict):
247
254
'old_type': <class 'list'>,
248
255
'old_value': [1, 2, 3]}}}
249
256
257
+ And if you don't care about the value of items that have changed type, please set verbose level to 0
258
+ >>> t1 = {1:1, 2:2, 3:3}
259
+ >>> t2 = {1:1, 2:"2", 3:3}
260
+ >>> pprint(DeepDiff(t1, t2, verbose_level=0), indent=2)
261
+ { 'type_changes': { 'root[2]': { 'new_type': <class 'str'>,
262
+ 'old_type': <class 'int'>}}}
263
+
250
264
List difference
251
265
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3, 4]}}
252
266
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2]}}
0 commit comments