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