Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9265
| Date | 2011-07-11 19:06 +0200 |
|---|---|
| From | Thomas Jollans <t@jollybox.de> |
| Subject | Re: Property setter and lambda question |
| References | <CAAyd8cncdj0CStxZdWDcpWCjjEd7WVA=m-CQ0H988zuv52SwMg@mail.gmail.com> <4E1B238B.7050607@jollybox.de> <CAAyd8cnypAUDE4A95YAdpppWp7yCD9cTKCFhUxqvfEUHjxczBQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.908.1310403973.1164.python-list@python.org> (permalink) |
# 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?
"""
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Property setter and lambda question Thomas Jollans <t@jollybox.de> - 2011-07-11 19:06 +0200
csiph-web