-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator_and_function.py
More file actions
39 lines (32 loc) · 1 KB
/
iterator_and_function.py
File metadata and controls
39 lines (32 loc) · 1 KB
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
39
import csv
import os
import re
from os.path import relpath
from typing import Optional
def iterator(name: str) -> Optional[str]:
"""create a csv"""
names = os.listdir(os.path.join("Dataset", name))
for i in range(len(names)):
yield os.path.join("Dataset", name, names[i]) # делаем итератор
return None
class Iterator:
def __init__(self, way_to_csv_file: str, name_class: str):
self.name_class = str(name_class)
self.list = []
self.way_to_file = way_to_csv_file
self.counter = 0
file = open(self.way_to_file, "r")
reader = csv.reader(file, delimiter="\t")
for row in reader:
if str(row)[-3] == self.name_class:
self.list.append(row)
def __iter__(self):
return self
def __next__(self):
if self.counter < len(self.list):
self.counter += 1
return self.list[self.counter - 1]
else:
return ""
for i in iterator("5"):
print(i)