From: Pierre GM <pgm...@gm...> - 2006-10-28 10:19:16
|
On Friday 27 October 2006 22:18, Michael McNeil Forbes wrote: > Is the following the desired behaviour for setting recarray attributes?=A0 I ran into the same problem recently... What about modifying __setattr__ to the following ? def __setattr__(self, attr, val): fielddict =3D sb.ndarray.__getattribute__(self,'dtype').fields if attr in fielddict.keys(): return sb.ndarray.__setitem__(self, attr, val) try: return object.__setattr__(self, attr, val) except AttributeError: # Must be a fieldname raise AttributeError, "record array has no attribute %s" % attr= =20 The order is changed, as in Michael's suggestion, but that doesn't set any= =20 variable in the __dict__, nor does it mask anything. Instead of modifying t= he=20 an attribute, we modify the field directly... |