no_data_desc_1.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import time
  2. from datetime import datetime
  3. class Time:
  4. def __get__(self, instance, owner_class):
  5. print('get access to __get__ method')
  6. print(f'self = {self}')
  7. print(f'instance = {instance}')
  8. print(f'owner_class = {owner_class}')
  9. return datetime.now().isoformat()
  10. '''
  11. class Time:
  12. def __get__(self, instance, owner_class):
  13. if instance is None:
  14. return self
  15. else:
  16. return datetime.now().isoformat()
  17. # Тоже, но через свойства
  18. # @property
  19. # def current_time(self):
  20. # return datetime.now().isoformat()
  21. '''
  22. class Logger:
  23. current_time = Time()
  24. # Есил current_time = @property
  25. # current_time = Time().current_time
  26. def main():
  27. # log = Logger()
  28. # print(log.current_time)
  29. # time.sleep(2)
  30. # print(log.current_time)
  31. print(Logger.current_time)
  32. # log = Logger()
  33. # print(log.current_time)
  34. if __name__ == '__main__':
  35. main()