@@ -49,10 +49,10 @@ Suppose we have a dictionary like this:
4949 x = {
5050 " a" : {
5151 " b" : {
52- " 3" : 2 ,
53- " 43" : 30 ,
54- " c" : [],
55- " d" : [' red' , ' buggy' , ' bumpers' ],
52+ " 3" : 2 ,
53+ " 43" : 30 ,
54+ " c" : [],
55+ " d" : [' red' , ' buggy' , ' bumpers' ],
5656 }
5757 }
5858 }
@@ -96,26 +96,26 @@ elements in ``x['a']['b']`` where the key is equal to the glob ``'[cd]'``. Okay.
9696.. code-block :: pycon
9797
9898 >>> result = dpath.util.search(x, "a/b/[cd]")
99- >>> print json.dumps(result, indent=4, sort_keys=True)
99+ >>> print( json.dumps(result, indent=4, sort_keys=True) )
100100 {
101- "a": {
102- "b": {
103- "c": [],
104- "d": [
105- "red",
106- "buggy",
107- "bumpers"
108- ]
101+ "a": {
102+ "b": {
103+ "c": [],
104+ "d": [
105+ "red",
106+ "buggy",
107+ "bumpers"
108+ ]
109+ }
109110 }
110111 }
111- }
112112
113113 ... Wow that was easy. What if I want to iterate over the results, and
114114not get a merged view?
115115
116116.. code-block :: pycon
117117
118- >>> for x in dpath.util.search(x, "a/b/[cd]", yielded=True): print x
118+ >>> for x in dpath.util.search(x, "a/b/[cd]", yielded=True): print(x)
119119 ...
120120 ('a/b/c', [])
121121 ('a/b/d', ['red', 'buggy', 'bumpers'])
@@ -154,7 +154,7 @@ value 'Waffles'.
154154
155155 >>> dpath.util.set(x, 'a/b/[cd]', 'Waffles')
156156 2
157- >>> print json.dumps(x, indent=4, sort_keys=True)
157+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
158158 {
159159 "a": {
160160 "b": {
@@ -188,7 +188,7 @@ necessary to get to the terminus.
188188 keys
189189
190190 >>> dpath.util.new(x, 'a/b/e/f/g', "Roffle")
191- >>> print json.dumps(x, indent=4, sort_keys=True)
191+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
192192 {
193193 "a": {
194194 "b": {
@@ -213,7 +213,7 @@ object with None entries in order to make it big enough:
213213
214214 >>> dpath.util.new(x, 'a/b/e/f/h', [])
215215 >>> dpath.util.new(x, 'a/b/e/f/h/13', 'Wow this is a big array, it sure is lonely in here by myself')
216- >>> print json.dumps(x, indent=4, sort_keys=True)
216+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
217217 {
218218 "a": {
219219 "b": {
@@ -290,59 +290,59 @@ does.
290290 replaces the destination in this situation.
291291
292292 >>> y = {'a': {'b': { 'e': {'f': {'h': [None, 0, 1, None, 13, 14]}}}, 'c': 'RoffleWaffles'}}
293- >>> print json.dumps(y, indent=4, sort_keys=True)
293+ >>> print( json.dumps(y, indent=4, sort_keys=True) )
294294 {
295- "a": {
296- "b": {
297- "e": {
298- "f": {
299- "h": [
300- null,
301- 0,
302- 1,
303- null,
304- 13,
305- 14
306- ]
307- }
295+ "a": {
296+ "b": {
297+ "e": {
298+ "f": {
299+ "h": [
300+ null,
301+ 0,
302+ 1,
303+ null,
304+ 13,
305+ 14
306+ ]
307+ }
308+ }
309+ },
310+ "c": "RoffleWaffles"
308311 }
309- },
310- "c": "RoffleWaffles"
311- }
312312 }
313313 >>> dpath.util.merge(x, y)
314- >>> print json.dumps(x, indent=4, sort_keys=True)
314+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
315315 {
316- "a": {
317- "b": {
318- "3": 2,
319- "43": 30,
320- "c": "Waffles",
321- "d": "Waffles",
322- "e": {
323- "f": {
324- "g": "Roffle",
325- "h": [
326- null,
327- 0,
328- 1,
329- null,
330- 13,
331- 14,
332- null,
333- null,
334- null,
335- null,
336- null,
337- null,
338- null,
339- "Wow this is a big array, it sure is lonely in here by myself"
340- ]
341- }
316+ "a": {
317+ "b": {
318+ "3": 2,
319+ "43": 30,
320+ "c": "Waffles",
321+ "d": "Waffles",
322+ "e": {
323+ "f": {
324+ "g": "Roffle",
325+ "h": [
326+ null,
327+ 0,
328+ 1,
329+ null,
330+ 13,
331+ 14,
332+ null,
333+ null,
334+ null,
335+ null,
336+ null,
337+ null,
338+ null,
339+ "Wow this is a big array, it sure is lonely in here by myself"
340+ ]
341+ }
342+ }
343+ },
344+ "c": "RoffleWaffles"
342345 }
343- },
344- "c": "RoffleWaffles"
345- }
346346 }
347347
348348 Now that's handy. You shouldn't try to use this as a replacement for the
@@ -369,41 +369,41 @@ them:
369369
370370.. code-block :: pycon
371371
372- >>> print json.dumps(x, indent=4, sort_keys=True)
372+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
373373 {
374- "a": {
375- "b": {
376- "3": 2,
377- "43": 30,
378- "c": "Waffles",
379- "d": "Waffles",
380- "e": {
381- "f": {
382- "g": "Roffle"
374+ "a": {
375+ "b": {
376+ "3": 2,
377+ "43": 30,
378+ "c": "Waffles",
379+ "d": "Waffles",
380+ "e": {
381+ "f": {
382+ "g": "Roffle"
383+ }
384+ }
383385 }
384386 }
385- }
386- }
387387 }
388388 >>> def afilter(x):
389389 ... if "ffle" in str(x):
390390 ... return True
391391 ... return False
392392 ...
393393 >>> result = dpath.util.search(x, '**', afilter=afilter)
394- >>> print json.dumps(result, indent=4, sort_keys=True)
394+ >>> print( json.dumps(result, indent=4, sort_keys=True) )
395395 {
396- "a": {
397- "b": {
398- "c": "Waffles",
399- "d": "Waffles",
400- "e": {
401- "f": {
402- "g": "Roffle"
396+ "a": {
397+ "b": {
398+ "c": "Waffles",
399+ "d": "Waffles",
400+ "e": {
401+ "f": {
402+ "g": "Roffle"
403+ }
404+ }
403405 }
404406 }
405- }
406- }
407407 }
408408
409409 Obviously filtering functions can perform more advanced tests (regular
0 commit comments