Advertisement
Guest User

Untitled

a guest
May 26th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. class Residents:
  2. __title = ['1', '1', '1', '1', '1', '1']
  3. __format = '{:>20} {:>10} {:>20} {:>20} {:>15} {:>15}\n'
  4.  
  5. def __init__(self):
  6. self.__data = []
  7. self.__index = 0
  8.  
  9. def __str__(self):
  10. return '\n'.join(' '.join(line) for line in self.__data)
  11.  
  12. def __iadd__(self, other):
  13. self.__data.append(other)
  14. return self
  15.  
  16. def __iter__(self):
  17. return self
  18.  
  19. def __next__(self):
  20. if self.__index >= len(self.__data):
  21. self.__index = 0
  22. raise StopIteration
  23. else:
  24. result = self.__data[self.__index]
  25. self.__index += 1
  26. return result
  27.  
  28. def print(self, file_name):
  29. file = open(file_name, 'w')
  30. file.write(self.__format.format(*self.__title))
  31. for line in self.__data:
  32. file.write(self.__format.format(*line))
  33. file.close()
  34.  
  35. def count_floor(self, floor):
  36. result = 0
  37. floor = str(floor)
  38. for line in self.__data:
  39. if line[1][:-2] == floor:
  40. result += 1
  41. return result
  42.  
  43. @property
  44. def len(self):
  45. return len(self.__data)
  46.  
  47.  
  48. residents = Residents()
  49.  
  50. file = open('input.txt', 'r')
  51. for line in file:
  52. residents += line.rstrip().split(';')
  53. file.close()
  54.  
  55. print('__str__:\n', residents, '\n', sep='')
  56.  
  57. print('__next__ & __iter__:')
  58. for elem in residents:
  59. print(elem)
  60. print()
  61.  
  62. residents.print('output.txt')
  63.  
  64. print(':', residents.count_floor(2))
  65.  
  66. print(':', residents.len)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement