How do you access the "private" variable behind a Python property?
In the following code, I get Hello World instead of the World World that I expect. I would guess that the property has a different scope that results in self being different in the property than the module. If so, is there a way to access the underlying variable? Or is there a different idiom to use for "code outside the class should use a different getter than code in the class"?
class Foo(): def __init__(self): self._x = 'Hello' self.x = 'World' @property def x(self): return self._x @x.setter def x(self, val): self._x = val foo = Foo() print(foo._x) print(foo.x)