Alan Gauld wrote: > "Vincent Gulinao" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Sorry about that. I want something like: >> >> class foo: >> >> def __init__(self): >> self.attr1 = None >> def get_attr1(self): >> if not self.attr1: >> attr1 = <get value from DB, very expensive query> >> self.attr1 = attr1 >> return self.attr1 >> >> such that: >> foo_instance = foo() >> foo_instance.get_attr1() >> foo_instance.attr1 >> >> gets the same value. > > > That looks like an ideal candidate for a "property".
I guess the requirements are still not clear. If there is just one attribute to be read from the database, a property will work well. If the OP wants to delegate many attributes, the __getattr__ approach might be simpler. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor