Jean-Michel Pichavant <jeanmic...@sequans.com> writes: [...] > While all these proposals are giving interesting technical anwsers to > the OP problem, I think that the OP original code is still the best > (_imo_). > > class Foo(object): > def __init__(self): > self.template_filename = "%s.tmpl" % self.__class__.__name__ > self.template_body = read_body_from(self.template_filename) > > > That is true the same attributes are defined for every instance, but, > honestly, who cares ? (unless you target the best class design 2010 > price :-) )
You might care if you have many instances but few classes, and the size of template_body is significant. Although with this design it is possible to cache template bodies within the 'read_body_from' function if necessary. Also I was under the impression that the OP wanted these attribute to be accessible from the class object as well. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list