Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9270

Re: Property setter and lambda question

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 <ian.g.kelly@gmail.com>
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 <CAAyd8cmPuKKFuhjQR1HDdv+P4doWtuRFHRQu3sPyMJ5pG_+Tew@mail.gmail.com>
References <CAAyd8cncdj0CStxZdWDcpWCjjEd7WVA=m-CQ0H988zuv52SwMg@mail.gmail.com> <4E1B238B.7050607@jollybox.de> <CAAyd8cnypAUDE4A95YAdpppWp7yCD9cTKCFhUxqvfEUHjxczBQ@mail.gmail.com> <4E1B2D7D.4030000@jollybox.de> <CAAyd8cmPuKKFuhjQR1HDdv+P4doWtuRFHRQu3sPyMJ5pG_+Tew@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 11 Jul 2011 11:41:41 -0600
Subject Re: Property setter and lambda question
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.913.1310406132.1164.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong
<anthony.hw.kong@gmail.com> wrote:
> Awesome, Thomas. The trick only works if there is only one leading
> underscore in the method names.
> The following example works as I expected for the derived class B.
> class A(object):
>     def __init__(self):
>         self.__not_here = 1
>     def _get_not_here(self):
>         return self.__not_here
>     def _set_not_here(self, v):
>         print "I am called"
>         self.__not_here = v
>     not_here = property(lambda self: self._get_not_here(), lambda self, v:
> self._set_not_here(v))
> class B(A):
>     def _set_not_here(self, v):
>         print "version B"
>         self.__not_here = 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).

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Property setter and lambda question Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-11 11:41 -0600

csiph-web