ex_2.py 602 B

1234567891011121314151617181920212223242526272829
  1. class IntegerValue:
  2. def __set__(self, instance, value):
  3. print('__set__ called')
  4. def __get__(self, instance, owner_class):
  5. print('__get__ called')
  6. class Point:
  7. x = IntegerValue()
  8. def test_1():
  9. p = Point()
  10. p.x = 100 # вызывает __set__ у дескриптора
  11. p.x # вызывает __get__ у дескриптора
  12. print(p.__dict__)
  13. p.__dict__['x'] = [10, 20, 30]
  14. print(p.__dict__)
  15. print(p.x)
  16. p.x = 200
  17. print(p.__dict__)
  18. def main():
  19. test_1()
  20. if __name__ == '__main__':
  21. main()