-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_loader.py
More file actions
39 lines (26 loc) · 838 Bytes
/
data_loader.py
File metadata and controls
39 lines (26 loc) · 838 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
from abc import abstractmethod
import csv
class ILoader:
@abstractmethod
def load(self, filename: str):
pass
class CSVLoader(ILoader):
def __init__(self) -> None:
super().__init__()
def load(self, filename: str):
res = []
with open(filename, 'r') as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
res.append(row)
return res
class TSVLoader(ILoader):
def __init__(self) -> None:
super().__init__()
def load(self, filename: str, fieldnames=None):
res = []
with open(filename, 'r', encoding="utf8") as tsv_file:
reader = csv.DictReader(tsv_file, dialect='excel-tab', fieldnames=fieldnames)
for row in reader:
res.append(row)
return res