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


Groups > comp.lang.python > #9270

Re: Property setter and lambda question

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 2011-07-11 11:41 -0600
Subject Re: Property setter and lambda question
Newsgroups comp.lang.python
Message-ID <mailman.913.1310406132.1164.python-list@python.org> (permalink)

Show all headers | 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