Dear Tutors,
I noticed that when you make a property to represent a mutable value
*class Obj(object):
def get(self):
print 'Get'
return self.prop
def set(self, new):
print 'Set'
self.prop = new
prop = property(get, set)
test = Obj()
test.prop = ['Hello']
*
and then try and use one of its methods.
*test.prop.append('World')
*It will treat it as a get, not a set.
*Output: Get
*Even thou you are basically changing its value.
*Before: ['Hello']
After: ['Hello', 'World']
*I know this happens because I'm not technically setting it to something
else, just getting one of its properties.
I was wondering how to make it fire off set to for certain methods.
Sincerely,
Me
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor