On Mon, Dec 6, 2010 at 7:34 AM, John <[email protected]> wrote: > Hello all, > > I have been using this class extensively in my modules / scripts. It > provides the ability to .reference dictionary values. I find it handy, > but am afraid it may come back to haunt me at some point. Is there > anything wrong with using this? > > > class Structure(dict): > """ A 'fancy' dictionary. It provides 'MatLab' structure-like > referencing. Could also just define a generic class. > Caution: This may be deprecated in a future release. > """ > def __getattr__(self, attr): > # Fake a __getstate__ method that resturns None > if attr == "__getstate__": > return lambda: None >
why not "return None"? > return self[attr] > def __setattr__(self, attr, value): > self[attr] = value > > def set_with_dict(self,D): > """ set attributes with a dict """ > for k in D.keys(): > self.__setattr__(k,D[k]) > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Joel Goldstick
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
