Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Residents:
- __title = ['1', '1', '1', '1', '1', '1']
- __format = '{:>20} {:>10} {:>20} {:>20} {:>15} {:>15}\n'
- def __init__(self):
- self.__data = []
- self.__index = 0
- def __str__(self):
- return '\n'.join(' '.join(line) for line in self.__data)
- def __iadd__(self, other):
- self.__data.append(other)
- return self
- def __iter__(self):
- return self
- def __next__(self):
- if self.__index >= len(self.__data):
- self.__index = 0
- raise StopIteration
- else:
- result = self.__data[self.__index]
- self.__index += 1
- return result
- def print(self, file_name):
- file = open(file_name, 'w')
- file.write(self.__format.format(*self.__title))
- for line in self.__data:
- file.write(self.__format.format(*line))
- file.close()
- def count_floor(self, floor):
- result = 0
- floor = str(floor)
- for line in self.__data:
- if line[1][:-2] == floor:
- result += 1
- return result
- @property
- def len(self):
- return len(self.__data)
- residents = Residents()
- file = open('input.txt', 'r')
- for line in file:
- residents += line.rstrip().split(';')
- file.close()
- print('__str__:\n', residents, '\n', sep='')
- print('__next__ & __iter__:')
- for elem in residents:
- print(elem)
- print()
- residents.print('output.txt')
- print(':', residents.count_floor(2))
- print(':', residents.len)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement