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


Groups > comp.lang.python > #9265 > unrolled thread

Re: Property setter and lambda question

Started byThomas Jollans <t@jollybox.de>
First post2011-07-11 19:06 +0200
Last post2011-07-11 19:06 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Property setter and lambda question Thomas Jollans <t@jollybox.de> - 2011-07-11 19:06 +0200

#9265 — Re: Property setter and lambda question

FromThomas Jollans <t@jollybox.de>
Date2011-07-11 19:06 +0200
SubjectRe: Property setter and lambda question
Message-ID<mailman.908.1310403973.1164.python-list@python.org>
# On 07/11/2011 06:53 PM, Anthony Kong wrote:
# But decorator! Of course! Thanks for reminding me this.
#
# In your example, where does '@not_here' come from? (Sorry, this syntax
# is new to me)

class A(object):
    def __init__(self):
        self.not_here = 1

     @property
     def not_here(self):
         return self.__not_here

     @not_here.setter
     def not_here(self, val):
         self.__not_here = val

"""
Let's translate that to non-decorator Python:
"""

class A(object):
    def __init__(self):
        self.not_here = 1

    def _(self):
        return self.__not_here
    not_here = property(_)
    del _

    def _(self, val):
        self.__not_here = val
    not_here = not_here.setter(_)
    del _


"""
@not_here.setter exists because not_here.setter exists. not_here exists
since we set it (when the getter/property was set).


Cheers
Thomas


PS: are you sure the lambda self: self.__foo() trick works, with
subclasses or otherwise? I haven't tested it, and I'm not saying it
doesn't, but I have a feeling double-underscore name mangling might be a
problem somewhere down the line?

"""

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web