I am running the following code:
class testClass:
def __init__(self, left, width):
self.__left = left
self.__width = width
@property
def left(self):
return self.__left
@left.setter
def left(self, newValue):
self.__left = newValue
@property
def width(self):
return self.__width
@width.setter
def width(self, newValue):
self.__width = newValue
def right(self):
return self.__width + self.__left
def rightFixed(self):
return self.width + self.left
test = testClass(10,5)
test.left = 50
print test.right()
print test.rightFixed()
I am getting the values
15
55
Can anyone explain why the first method test.right() is giving the value 15, whereas if I call the test.rightFixed() value it gives me the appropriate value? I have looked in the interpreter, and _testClass__left after the code has run gives me 10, whereas it should give me 50. The @left.setter property doesn't seem to be updating the self.__left, rather it seems to be making it's own copy.
EDIT: I should also note, I am running 2.7.6. As Games Brainiac pointed out, this works fine in python 3+.