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


Groups > comp.lang.python > #109702

what is wrong with this property setter

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Nagy László Zsolt <gandalf@shopzeus.com>
Newsgroups comp.lang.python
Subject what is wrong with this property setter
Date Thu, 9 Jun 2016 09:28:34 +0200
Lines 42
Message-ID <mailman.91.1465457313.2306.python-list@python.org> (permalink)
References <bc685f14-106c-4d3f-38f9-262e05b896d7@shopzeus.com>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-2
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de iSUeQmym/wpB1WWVpisRQA9mby+rW9xop/ZscsdnH1Pw==
Return-Path <gandalf@shopzeus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.037
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; '@property': 0.09; 'def': 0.13; 'btw': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'test()': 0.16; 'attribute': 0.18; 'to:name:python- list@python.org': 0.20; 'work,': 0.21; '(most': 0.24; 'subject:what': 0.29; '15,': 0.30; "can't": 0.32; 'skip:_ 10': 0.32; 'class': 0.33; 'traceback': 0.33; 'file': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'skip:p 20': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'charset:iso-8859-2': 0.64; 'subject:this': 0.85
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopzeus.com; s=shopzeus_com; t=1465457312; bh=V6kCvyJd/lsoEO+xXRuKHcbP8vQiUnr4EZi81zwE8NM=; h=To:From:Subject:Date:From; b=LRsVoYZr6mBtStIDFq4WGcDR7kQnFPLLoB6z9r0KwbyNo0aBmSqo9l7BASme+QpRb f0b1MhVtaBpKaMrJvKT4DXgfTUQnRX0GQBI48xZYKUQdiC2gBhWOJPQbi2MgoXbFWU FBGH5vxW06p4nUyW/R74CvYvKG1BuMG5UKnzenRb7BFoXym7DWdpGaHNYGjaBq+JfF Ra9Z4HqFX+l/lWYf2aX3Tj385J2VvbOrL8J/NPQqKoOB+V1dhkHjlel1wRbBH9zuWf NghFZ77Xvx7E+Hykw+pGRBB6nGiZK25/ExPJT9nnFdXpKwSQx0tXkwVimXiZ36OlPW Xv3sg687d15Dg==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <bc685f14-106c-4d3f-38f9-262e05b896d7@shopzeus.com>
Xref csiph.com comp.lang.python:109702

Show key headers only | View raw


class Test:
    def __init__(self):
        self._parent = None

    @property
    def parent(self):
        return self._parent

    @parent.setter
    def set_parent(self, new_parent):
        self._parent = new_parent


p, c = Test(), Test()
c.parent = p

>py -3 test.py

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    c.parent = p
AttributeError: can't set attribute

BTW this does work, but it is not that elegant:

class Test:
    def __init__(self):
        self._parent = None

    def get_parent(self):
        return self._parent

    def set_parent(self, new_parent):
        self._parent = new_parent

    parent = property(get_parent, set_parent)


p, c = Test(), Test()
c.parent = p

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


Thread

what is wrong with this property setter Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-09 09:28 +0200
  Re: what is wrong with this property setter Mark Summerfield <list@qtrac.plus.com> - 2016-06-09 00:49 -0700
  Re: what is wrong with this property setter Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-09 17:52 +1000

csiph-web