Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.054 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'derived': 0.09; 'am,': 0.13; 'wrote:': 0.15; '(when': 0.16; 'input,': 0.16; 'it).': 0.16; 'lambda': 0.16; 'mon,': 0.16; 'def': 0.16; 'subject:question': 0.21; 'modify': 0.22; 'header:In-Reply-To:1': 0.22; 'convenience': 0.23; 'pair': 0.23; 'bit': 0.28; 'message-id:@mail.gmail.com': 0.28; 'classes': 0.30; 'anthony': 0.30; 'version': 0.30; 'thanks': 0.31; 'class': 0.31; 'to:addr:python-list': 0.34; 'there': 0.34; 'normally': 0.34; 'skip:b 40': 0.34; 'received:google.com': 0.38; 'received:209.85.161': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'easier': 0.39; 'allows': 0.39; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'your': 0.60; '11,': 0.68; 'kong': 0.84; 'self:': 0.84; 'subject:Property': 0.84; 'value):': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=ZmJm39+jqVXuIHF8e/p0NT5L13z3VLBbt3QpouOIUhY=; b=U1LLvTZGGGq78Igwx+CcU5xSLgU7CisFouIIaBmZi/0RcU/Q8rd8hPBxuoqkfhd/tc ZZIhzs+AfgquuOcAbY7rMn4JmakEfS/zWmP7zEVNsoEgypFXWYcmqpxi4uCq1ZzBLexg 5qWCPxxmJD/K7bYkUfxWStyr7B4ud3tVifCsY= MIME-Version: 1.0 In-Reply-To: References: <4E1B238B.7050607@jollybox.de> From: Ian Kelly Date: Mon, 11 Jul 2011 11:35:05 -0600 Subject: Re: Property setter and lambda question To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310405736 news.xs4all.nl 21828 [2001:888:2000:d::a6]:33490 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9269 On Mon, Jul 11, 2011 at 10:53 AM, Anthony Kong wrote: > Thanks again for your input, Thomas. > I normally prefer > not_here =3D property(lambda self: self.__get_not_here(), lambda self,=A0= v: > self.__set_not_here(v)) > than > not_here =3D property(__get_not_here, __set_not_here) > Because it allows me to have a pair getter/setter (when there is a need f= or > it). Use of lambda there is ensure derived class of A can provide their > custom version of getter/setter. The .setter convenience method also makes it a bit easier for derived classes to modify getters and setters: class Base(object): def get_my_property(self): return self._my_property def set_my_property(self, value): self._my_property =3D value my_property =3D property(get_my_property, set_my_property) class Derived(Base): def set_my_property(self, value): super(Derived, self).set_my_property(convert(value)) my_property =3D Base.my_property.setter(set_my_property)