Sick problem with Python properties

W

webmaster

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top