-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5.py
More file actions
34 lines (26 loc) · 814 Bytes
/
task5.py
File metadata and controls
34 lines (26 loc) · 814 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
import os
import csv
class Iterator:
def __init__(self, class_name):
self.counter = 0
self.class_name = class_name
self.data = os.listdir(os.path.join('dataset', self.class_name))
self.limit = len(self.data)
def __iter__(self):
return self
def __next__(self):
if self.counter < self.limit:
next_path = os.path.join(self.class_name, self.data[self.counter])
self.counter += 1
return next_path
else:
return None
if __name__ == "__main__":
polarbears = Iterator('polarbear')
brownbears = Iterator('brownbear')
print(next(polarbears))
print(next(polarbears))
print(next(polarbears))
print(next(brownbears))
print(next(brownbears))
print(next(brownbears))