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.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'attribute': 0.09; 'derived': 0.09; 'am,': 0.13; 'wrote:': 0.15; 'lambda': 0.16; 'self,': 0.16; 'underscore': 0.16; 'mon,': 0.16; 'def': 0.16; 'subject:question': 0.21; 'header:In-Reply-To:1': 0.22; 'vs.': 0.23; 'skip:_ 20': 0.28; 'message-id:@mail.gmail.com': 0.28; 'example': 0.30; 'anthony': 0.30; 'version': 0.30; 'class': 0.31; 'print': 0.32; 'setting': 0.32; 'to:addr:python-list': 0.34; 'there': 0.34; 'received:google.com': 0.38; 'received:209.85.161': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; '8bit%:12': 0.38; 'got': 0.39; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; '11,': 0.68; 'awesome,': 0.84; 'kong': 0.84; 'self:': 0.84; 'subject:Property': 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=x0cZv/aJdVp/KvDYdwyJrLTumRfOew/o7PLDgN/p29c=; b=L5IgE1ODbDXjMBI5+G4TDQSpwqS1LjXLh71wF/HbPH6VIHd4elgFz0k/CWhsnoJdMh 1TpGmHHl5EQnsad834WRT2KWCJCQwGFH9kfJwXVfN37iACjeUFg+w7CvJdShSlBijVgT Suu9gnWE6+VGvJzwoL8V7gj14LkX+S/dFnT6M= MIME-Version: 1.0 In-Reply-To: References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> From: Ian Kelly Date: Mon, 11 Jul 2011 11:41:41 -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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310406132 news.xs4all.nl 21752 [2001:888:2000:d::a6]:55019 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9270 On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong wrote: > Awesome, Thomas. The trick only works if there is only=A0one=A0leading > underscore in the=A0method=A0names. > The following example works as I expected for the derived class B. > class A(object): > =A0 =A0 def __init__(self): > =A0 =A0 =A0 =A0 self.__not_here =3D 1 > =A0 =A0 def _get_not_here(self): > =A0 =A0 =A0 =A0 return self.__not_here > =A0 =A0 def _set_not_here(self, v): > =A0 =A0 =A0 =A0 print "I am called" > =A0 =A0 =A0 =A0 self.__not_here =3D v > =A0 =A0 not_here =3D property(lambda self: self._get_not_here(), lambda s= elf, v: > self._set_not_here(v)) > class B(A): > =A0 =A0 def _set_not_here(self, v): > =A0 =A0 =A0 =A0 print "version B" > =A0 =A0 =A0 =A0 self.__not_here =3D v It shouldn't. You've still got the name __not_here used in both A and B, so that the B version is setting a different attribute than the A version (_B__not_here vs. _A__not_here).