On Sun, 24 May 2009 05:06:13 -0700 (PDT) Kless <jonas....@googlemail.com> wrote:
> Is there any way to simplify the next code? Because I'm setting a > variable by default of the same way than it's set in the setter. > > ------------------- > class Foo(object): > def __init__(self, bar): > self._bar = self._change(bar) # !!! as setter Guess it's obvious, but why not use "setattr(self, 'bar', bar)" here, in __init__ - it'll just call defined setter. > @property > def bar(self): > return self._bar > > @bar.setter > def bar(self, bar): > self._bar = self._change(bar) # !!! as in init > > def _change(self, text): > return text + 'any change' > ------------------- -- Mike Kazantsev // fraggod.net
signature.asc
Description: PGP signature
-- http://mail.python.org/mailman/listinfo/python-list