3 ms·
Another one: class A(): def __init__(self): self._x = 0 @property def x(self): return self._x @x.setter
by tomp 13y ago
Another one:
class A():
def __init__(self):
self._x = 0
@property
def x(self):
return self._x
@x.setter
def x(self, new_value):
self._x = new_value
Using it:
a = A()
print a._x # 0
print a.x # 0
a.x = 4
print a.x # 4
print a._x # 0 wait WTF?!
The bug was not having `A` inherit from `object`. With old-style classes, properties do not work correctly.