-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.py
More file actions
38 lines (31 loc) · 1017 Bytes
/
iterator.py
File metadata and controls
38 lines (31 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import csv
class Iterator:
"""Класс итератор - задаётся итерируемый объект и датасет"""
def __init__(self, label: str, file: str) -> None:
self.label = label
self.file = file
self.score = 0
self.data = []
with open(self.file) as reading_file:
file_reader = csv.reader(reading_file, delimiter=";")
for i in file_reader:
if i[2] == self.label:
self.data.append(i[0])
self.full = len(self.data)
def __iter__(self):
return self
def __next__(self):
if self.score < self.full:
i = self.score
self.score += 1
return self.data[i]
else:
raise StopIteration
def main():
instance = Iterator("dog", "dataset_csv.csv")
print(next(instance))
print(next(instance))
print(next(instance))
print(next(instance))
if __name__ == "__main__":
main()