The decorator propertyonly works with new-style classes. In Python 2.x, you need to extend the class object:
class A(object):
def __init__(self):
self.__var = 5
def get_var(self):
return self.__var
def set_var(self, value):
self.__var = value
var = property(get_var, set_var)
Without the behavior of the new-style class, assignment a.var = 10simply associates the new value ( 10) with the new attribute of the element a.var.
source
share