Show More
@@ -163,8 +163,22 b' class Struct:' | |||
|
163 | 163 | return self.__dict__[key] |
|
164 | 164 | |
|
165 | 165 | def __contains__(self,key): |
|
166 |
"""Allows use of the 'in' operator. |
|
|
167 | return self.__dict__.has_key(key) | |
|
166 | """Allows use of the 'in' operator. | |
|
167 | ||
|
168 | Examples: | |
|
169 | >>> s = Struct(x=1) | |
|
170 | >>> 'x' in s | |
|
171 | True | |
|
172 | >>> 'y' in s | |
|
173 | False | |
|
174 | >>> s[4] = None | |
|
175 | >>> 4 in s | |
|
176 | True | |
|
177 | >>> s.z = None | |
|
178 | >>> 'z' in s | |
|
179 | True | |
|
180 | """ | |
|
181 | return key in self.__dict__ | |
|
168 | 182 | |
|
169 | 183 | def __iadd__(self,other): |
|
170 | 184 | """S += S2 is a shorthand for S.merge(S2).""" |
@@ -246,12 +260,13 b' class Struct:' | |||
|
246 | 260 | Optionally, one or more key=value pairs can be given at the end for |
|
247 | 261 | direct update.""" |
|
248 | 262 | |
|
249 |
# The funny name __loc_data__ is to prevent a common variable name |
|
|
250 |
# could be a fieled of a Struct to collide with this |
|
|
251 |
# would arise if the function is called with a |
|
|
252 |
# that a user means to add as a Struct |
|
|
263 | # The funny name __loc_data__ is to prevent a common variable name | |
|
264 | # which could be a fieled of a Struct to collide with this | |
|
265 | # parameter. The problem would arise if the function is called with a | |
|
266 | # keyword with this same name that a user means to add as a Struct | |
|
267 | # field. | |
|
253 | 268 | newdict = Struct.__make_dict(self,__loc_data__,**kw) |
|
254 | for k,v in newdict.items(): | |
|
269 | for k,v in newdict.iteritems(): | |
|
255 | 270 | self[k] = v |
|
256 | 271 | |
|
257 | 272 | def merge(self,__loc_data__=None,__conflict_solve=None,**kw): |
General Comments 0
You need to be logged in to leave comments.
Login now