Show More
@@ -59,8 +59,8 b' class Struct(dict):' | |||||
59 | >>> s.b |
|
59 | >>> s.b | |
60 | 30 |
|
60 | 30 | |
61 | >>> s2 = Struct(s,c=30) |
|
61 | >>> s2 = Struct(s,c=30) | |
62 | >>> s2.keys() |
|
62 | >>> sorted(s2.keys()) | |
63 |
['a', ' |
|
63 | ['a', 'b', 'c'] | |
64 | """ |
|
64 | """ | |
65 | object.__setattr__(self, '_allownew', True) |
|
65 | object.__setattr__(self, '_allownew', True) | |
66 | dict.__init__(self, *args, **kw) |
|
66 | dict.__init__(self, *args, **kw) | |
@@ -161,8 +161,8 b' class Struct(dict):' | |||||
161 | >>> s = Struct(a=10,b=30) |
|
161 | >>> s = Struct(a=10,b=30) | |
162 | >>> s2 = Struct(a=20,c=40) |
|
162 | >>> s2 = Struct(a=20,c=40) | |
163 | >>> s += s2 |
|
163 | >>> s += s2 | |
164 | >>> s |
|
164 | >>> sorted(s.keys()) | |
165 | {'a': 10, 'c': 40, 'b': 30} |
|
165 | ['a', 'b', 'c'] | |
166 | """ |
|
166 | """ | |
167 | self.merge(other) |
|
167 | self.merge(other) | |
168 | return self |
|
168 | return self | |
@@ -176,8 +176,8 b' class Struct(dict):' | |||||
176 | >>> s1 = Struct(a=10,b=30) |
|
176 | >>> s1 = Struct(a=10,b=30) | |
177 | >>> s2 = Struct(a=20,c=40) |
|
177 | >>> s2 = Struct(a=20,c=40) | |
178 | >>> s = s1 + s2 |
|
178 | >>> s = s1 + s2 | |
179 | >>> s |
|
179 | >>> sorted(s.keys()) | |
180 | {'a': 10, 'c': 40, 'b': 30} |
|
180 | ['a', 'b', 'c'] | |
181 | """ |
|
181 | """ | |
182 | sout = self.copy() |
|
182 | sout = self.copy() | |
183 | sout.merge(other) |
|
183 | sout.merge(other) | |
@@ -241,10 +241,8 b' class Struct(dict):' | |||||
241 |
|
241 | |||
242 | >>> s = Struct(a=10,b=30) |
|
242 | >>> s = Struct(a=10,b=30) | |
243 | >>> s2 = s.copy() |
|
243 | >>> s2 = s.copy() | |
244 | >>> s2 |
|
244 | >>> type(s2) is Struct | |
245 | {'a': 10, 'b': 30} |
|
245 | True | |
246 | >>> type(s2).__name__ |
|
|||
247 | 'Struct' |
|
|||
248 | """ |
|
246 | """ | |
249 | return Struct(dict.copy(self)) |
|
247 | return Struct(dict.copy(self)) | |
250 |
|
248 | |||
@@ -348,8 +346,8 b' class Struct(dict):' | |||||
348 | >>> s = Struct(a=10,b=30) |
|
346 | >>> s = Struct(a=10,b=30) | |
349 | >>> s2 = Struct(a=20,c=40) |
|
347 | >>> s2 = Struct(a=20,c=40) | |
350 | >>> s.merge(s2) |
|
348 | >>> s.merge(s2) | |
351 | >>> s |
|
349 | >>> sorted(s.items()) | |
352 | {'a': 10, 'c': 40, 'b': 30} |
|
350 | [('a', 10), ('b', 30), ('c', 40)] | |
353 |
|
351 | |||
354 | Now, show how to specify a conflict dict: |
|
352 | Now, show how to specify a conflict dict: | |
355 |
|
353 | |||
@@ -357,8 +355,8 b' class Struct(dict):' | |||||
357 | >>> s2 = Struct(a=20,b=40) |
|
355 | >>> s2 = Struct(a=20,b=40) | |
358 | >>> conflict = {'update':'a','add':'b'} |
|
356 | >>> conflict = {'update':'a','add':'b'} | |
359 | >>> s.merge(s2,conflict) |
|
357 | >>> s.merge(s2,conflict) | |
360 | >>> s |
|
358 | >>> sorted(s.items()) | |
361 |
|
|
359 | [('a', 20), ('b', 70)] | |
362 | """ |
|
360 | """ | |
363 |
|
361 | |||
364 | data_dict = dict(__loc_data__,**kw) |
|
362 | data_dict = dict(__loc_data__,**kw) |
@@ -118,10 +118,10 b' def json_clean(obj):' | |||||
118 | 4 |
|
118 | 4 | |
119 | >>> json_clean(range(10)) |
|
119 | >>> json_clean(range(10)) | |
120 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|
120 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
121 | >>> json_clean(dict(x=1, y=2)) |
|
121 | >>> sorted(json_clean(dict(x=1, y=2)).items()) | |
122 | {'y': 2, 'x': 1} |
|
122 | [('x', 1), ('y', 2)] | |
123 | >>> json_clean(dict(x=1, y=2, z=[1,2,3])) |
|
123 | >>> sorted(json_clean(dict(x=1, y=2, z=[1,2,3])).items()) | |
124 |
|
|
124 | [('x', 1), ('y', 2), ('z', [1, 2, 3])] | |
125 | >>> json_clean(True) |
|
125 | >>> json_clean(True) | |
126 | True |
|
126 | True | |
127 | """ |
|
127 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now