Set a variable as in setter

Kless jonas.esp at googlemail.com
Sun May 24 19:53:53 CEST 2009


On 24 mayo, 15:33, Kless <jonas.... at googlemail.com> wrote:
> On 24 mayo, 12:27, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
>
> > Kless <jonas.... at 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
>
> > What's wrong with just doing this?:
> >         self.bar = bar
>
> Because 'bar' is going to be modified before of be saved.

Sorry! It works well. The problem was because I was using it from
iPython.



More information about the Python-list mailing list