How do you access the "private" variable behind a Python property?
In the following code, I get
self._x = 'Hello'
self.x = 'World'
def x(self, val):
self._x = val
foo = Foo()
You are accessing the private variable
What is typical in this situation is to not define the
x attribute at all, i.e. remove the line
self.x = 'World'. That way you are using the property
x to access the attribute
_x (and because privates aren't really private you can of course also access the attribute directly using
Edit: the first part of my answer was wrong, see user2357112's answer for why you are not getting the expected output.