@@ -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": {
@@ -291,59 +291,59 @@ does.
291291 replaces the destination in this situation.
292292
293293 >>> y = {'a': {'b': { 'e': {'f': {'h': [None, 0, 1, None, 13, 14]}}}, 'c': 'RoffleWaffles'}}
294- >>> print json.dumps(y, indent=4, sort_keys=True)
294+ >>> print( json.dumps(y, indent=4, sort_keys=True) )
295295 {
296- "a": {
297- "b": {
298- "e": {
299- "f": {
300- "h": [
301- null,
302- 0,
303- 1,
304- null,
305- 13,
306- 14
307- ]
308- }
296+ "a": {
297+ "b": {
298+ "e": {
299+ "f": {
300+ "h": [
301+ null,
302+ 0,
303+ 1,
304+ null,
305+ 13,
306+ 14
307+ ]
308+ }
309+ }
310+ },
311+ "c": "RoffleWaffles"
309312 }
310- },
311- "c": "RoffleWaffles"
312- }
313313 }
314314 >>> dpath.util.merge(x, y)
315- >>> print json.dumps(x, indent=4, sort_keys=True)
315+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
316316 {
317- "a": {
318- "b": {
319- "3": 2,
320- "43": 30,
321- "c": "Waffles",
322- "d": "Waffles",
323- "e": {
324- "f": {
325- "g": "Roffle",
326- "h": [
327- null,
328- 0,
329- 1,
330- null,
331- 13,
332- 14,
333- null,
334- null,
335- null,
336- null,
337- null,
338- null,
339- null,
340- "Wow this is a big array, it sure is lonely in here by myself"
341- ]
342- }
317+ "a": {
318+ "b": {
319+ "3": 2,
320+ "43": 30,
321+ "c": "Waffles",
322+ "d": "Waffles",
323+ "e": {
324+ "f": {
325+ "g": "Roffle",
326+ "h": [
327+ null,
328+ 0,
329+ 1,
330+ null,
331+ 13,
332+ 14,
333+ null,
334+ null,
335+ null,
336+ null,
337+ null,
338+ null,
339+ null,
340+ "Wow this is a big array, it sure is lonely in here by myself"
341+ ]
342+ }
343+ }
344+ },
345+ "c": "RoffleWaffles"
343346 }
344- },
345- "c": "RoffleWaffles"
346- }
347347 }
348348
349349 Now that's handy. You shouldn't try to use this as a replacement for the
@@ -370,41 +370,41 @@ them:
370370
371371.. code-block :: pycon
372372
373- >>> print json.dumps(x, indent=4, sort_keys=True)
373+ >>> print( json.dumps(x, indent=4, sort_keys=True) )
374374 {
375- "a": {
376- "b": {
377- "3": 2,
378- "43": 30,
379- "c": "Waffles",
380- "d": "Waffles",
381- "e": {
382- "f": {
383- "g": "Roffle"
375+ "a": {
376+ "b": {
377+ "3": 2,
378+ "43": 30,
379+ "c": "Waffles",
380+ "d": "Waffles",
381+ "e": {
382+ "f": {
383+ "g": "Roffle"
384+ }
385+ }
384386 }
385387 }
386- }
387- }
388388 }
389389 >>> def afilter(x):
390390 ... if "ffle" in str(x):
391391 ... return True
392392 ... return False
393393 ...
394394 >>> result = dpath.util.search(x, '**', afilter=afilter)
395- >>> print json.dumps(result, indent=4, sort_keys=True)
395+ >>> print( json.dumps(result, indent=4, sort_keys=True) )
396396 {
397- "a": {
398- "b": {
399- "c": "Waffles",
400- "d": "Waffles",
401- "e": {
402- "f": {
403- "g": "Roffle"
397+ "a": {
398+ "b": {
399+ "c": "Waffles",
400+ "d": "Waffles",
401+ "e": {
402+ "f": {
403+ "g": "Roffle"
404+ }
405+ }
404406 }
405407 }
406- }
407- }
408408 }
409409
410410 Obviously filtering functions can perform more advanced tests (regular
0 commit comments