1234567891011121314151617181920212223242526272829 |
- class IntegerValue:
- def __set__(self, instance, value):
- print('__set__ called')
- def __get__(self, instance, owner_class):
- print('__get__ called')
- class Point:
- x = IntegerValue()
- def test_1():
- p = Point()
- p.x = 100 # вызывает __set__ у дескриптора
- p.x # вызывает __get__ у дескриптора
- print(p.__dict__)
- p.__dict__['x'] = [10, 20, 30]
- print(p.__dict__)
- print(p.x)
- p.x = 200
- print(p.__dict__)
- def main():
- test_1()
- if __name__ == '__main__':
- main()
|