Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9269
| References | <CAAyd8cncdj0CStxZdWDcpWCjjEd7WVA=m-CQ0H988zuv52SwMg@mail.gmail.com> <4E1B238B.7050607@jollybox.de> <CAAyd8cnypAUDE4A95YAdpppWp7yCD9cTKCFhUxqvfEUHjxczBQ@mail.gmail.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2011-07-11 11:35 -0600 |
| Subject | Re: Property setter and lambda question |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.912.1310405736.1164.python-list@python.org> (permalink) |
On Mon, Jul 11, 2011 at 10:53 AM, Anthony Kong
<anthony.hw.kong@gmail.com> wrote:
> Thanks again for your input, Thomas.
> I normally prefer
> not_here = property(lambda self: self.__get_not_here(), lambda self, v:
> self.__set_not_here(v))
> than
> not_here = property(__get_not_here, __set_not_here)
> Because it allows me to have a pair getter/setter (when there is a need for
> 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 = value
my_property = 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 = Base.my_property.setter(set_my_property)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Property setter and lambda question Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-11 11:35 -0600
csiph-web