On 2005-07-07, George Sakkis <[EMAIL PROTECTED]> wrote: > I guess he means why not define foo as property: > > class demo(object): > foo = property(fget = lambda self: self.v, > fset = lambda self,v: setattr(self,'v',v)) > > d = demo() > d.foo = 3 > print d.foo
In some ways that's even cleaner. In my simplivied example all the foo() method was doing was setting/returning an attribute, but usually there's a bit more going on (e.g. system calls with possible side effects). To me it's a bit more explicit that d.foo(3) d.foo() are doing something other than just getting/setting the value of an instance attribute. If all I really wanted to do was get/set the instance's "v" attribute, I probably would have just done it like this d.v = 3 print d.v -- Grant Edwards grante Yow! .. I wonder if I at ought to tell them about my visi.com PREVIOUS LIFE as a COMPLETE STRANGER? -- http://mail.python.org/mailman/listinfo/python-list