property decorator?
Cholo Lennon
chololennon at hotmail.com
Thu Dec 21 10:08:49 EST 2017
On 20/12/17 21:39, Stefan Ram wrote:
> Irv Kalb <Irv at furrypants.com> writes:
> about property decorators.
>
> The code
>
> @property
> def salary(self): pass
>
> @salary.setter
> def salary(self, newSalary): pass
>
> is an abbreviation for
>
> def salary_get(self): pass
> salary = property( salary_get )
>
> def salary_set(self, newSalary): pass
> salary = salary.setter( salary_set )
>
> . »property« is a class, »property( salaray )« constructs an
> instance with salary_get as getter and no setter. Later,
> »salary.setter« adds »salaray_set« as a setter to that
> instance.
>
> One cannot use »@salary.getter« instead of »@property«,
> because at that point in time, the instance »salaray« does
> not already exist.
>
Best answser IMHO, it's clear and concise.
--
Cholo Lennon
Bs.As.
ARG
More information about the Python-list
mailing list