-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5.py
More file actions
64 lines (53 loc) · 2.07 KB
/
task5.py
File metadata and controls
64 lines (53 loc) · 2.07 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import csv
class Iterator1:
"""Initializing class fields"""
def __init__(self, path: str):
self.file_names = os.listdir(os.path.join('dataset', path))
self.counter = 0
self.limit = len(self.file_names)
self.path = path
def __next__(self):
if self.counter < self.limit:
self.counter += 1
return os.path.join(self.path, self.file_names[self.counter - 1])
else:
raise StopIteration
class Iterator2:
"""Initialization of class fields. Checking for the presence of the class name in the
file name, if it is missing the file is deleted"""
def __init__(self, class_name: str, path: str):
self.file_names = os.listdir(os.path.join(path))
for name in self.file_names:
if not class_name in name:
self.file_names.remove(name)
self.limit = len(self.file_names)
self.counter = 0
self.path = path
def __next__(self):
if self.counter < self.limit:
self.counter += 1
return os.path.join(self.path, self.file_names[self.counter - 1])
else:
raise StopIteration
class Iterator3:
"""Initialization of class fields. Reading elements from the csv file and writing them to the list"""
def __init__(self, class_name: str, path: str, annotation_name: str):
self.file_names = list()
with open(os.path.join(path, annotation_name), encoding='UTF-16') as file:
reader = csv.reader(file, delimiter=',')
for file_info in reader:
if file_info[1] == class_name:
self.file_names.append()
for name in self.file_names:
if not class_name in name:
self.file_names.remove(name)
self.limit = len(self.file_names)
self.counter = 0
self.path = path
def __next__(self):
if self.counter < self.limit:
self.counter += 1
return os.path.join(self.path, self.file_names[self.counter - 1])
else:
raise StopIteration