Guido van Rossum wrote: > OK, so how's this for a radical proposal. > > Let's change the property built-in so that its arguments can be either > functions or strings (or None). If they are functions or None, it > behaves exactly like it always has. > > If an argument is a string, it should be a method name, and the method > is looked up by that name each time the property is used. Because this > is late binding, it can be put before the method definitions, and a > subclass can override the methods. Example: > > class C: > > foo = property('getFoo', 'setFoo', None, 'the foo property') > > def getFoo(self): > return self._foo > > def setFoo(self, foo): > self._foo = foo > > What do you think?
+1 from here. > If you can think of a solution that looks better than mine, you're a genius. letting "class" inject a slightly magic "self" variable into the class namespace ? class C: foo = property(self.getFoo, self.setFoo, None, 'the foo property') def getFoo(self): return self._foo def setFoo(self, foo): self._foo = foo (figuring out exactly what "self" should be is left as an exercise etc) </F> _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com