python property用法

class TestPropertyDecorator(object):
def init(self, value):
self.x = value

@property
def x(self):
    return self._x

@x.setter
def x(self, value):
    if not (type(value) == int and 0 < value < 32):
        raise ValueError("TestProperty.x "
            "must be an integer between 0 and 32")
    self._x = value

你可能感兴趣的:(python property用法)