-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIterator.py
More file actions
47 lines (34 loc) · 918 Bytes
/
Iterator.py
File metadata and controls
47 lines (34 loc) · 918 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
39
40
41
42
43
44
45
46
47
import os
import csv
class Iterator:
def __init__(self, name_of_file: str) -> None:
"""Initialization
Args:
name_of_file (str): path to file to iterate
"""
self.name_of_file = name_of_file
self.counter = 0
self.list = []
file = open(self.name_of_file, "r", encoding='utf-8')
for row in file:
self.list.append(row)
file.close
def __iter__(self):
return self
def __next__(self) -> int:
"""next
Returns:
int: _description_
"""
if self.counter < len(self.list):
tmp = self.list[self.counter]
self.counter += 1
return tmp
else:
raise StopIteration
def main() -> None:
iter = Iterator("dataset.csv")
for i in range(1, 10):
print(next(iter))
if __name__ == '__main__':
main()