class property methods getting called only once

J

jm.suresh

In the following code, I could not find out why the set and get methods
are not called once I set the property.

.... def __init__(self):
.... self._color = 12
.... def _setcolor(self,value):
.... print 'setting'
.... self._color = value
.... def _getcolor(self):
.... print 'getting'
.... return self._color
.... color = property(_getcolor,_setcolor)
....
getting
12
22

For some reason the set method is not getting called at all, Anybody
has any clue?

thanks.
 
L

limodou

In the following code, I could not find out why the set and get methods
are not called once I set the property.


... def __init__(self):
... self._color = 12
... def _setcolor(self,value):
... print 'setting'
... self._color = value
... def _getcolor(self):
... print 'getting'
... return self._color
... color = property(_getcolor,_setcolor)
...
22

For some reason the set method is not getting called at all, Anybody
has any clue?

thanks.

property can only be used in New Style Class. So you should write your Test as:

class Test(object):

And try again.
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top