Sick problem with Python properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • webmaster@t-dose.de

    Sick problem with Python properties

    See the following code. I wonder why in this case neither
    setp() nor getp() is called !?


    yetix@/home/ajung(1)% cat test.py
    class A:

    def __init__(self):
    self._p=None

    def setp(self, p):
    print 'set'
    self._p = p*p

    def getp(self):
    print 'get'
    return self._p

    pp = property(getp, setp)


    inst=A()
    inst.p = 9
    print inst.p

    yetix@/home/ajung(2)% python2.3 test.py
    9

    Cheers,
    -aj



Working...