# setter、getter方法
class Text(object):
def __init__(self, name="Text"):
self.name = name
self._x = 0
self._y = 0
@property
def x(self):
print("property")
return self._x
@x.setter
def x(self, x=1):
print("setter")
self._x = x
# 如果写了 x.getter 方法, 那么在调用 Text().x 时, 将不会再运行 相应属性的 property方法
@x.getter
def x(self):
print("getter")
return self._x
some_text = Text("some_text")
some_text.x = 10
print(some_text.x)