-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvFile.py
More file actions
47 lines (40 loc) · 1.1 KB
/
CsvFile.py
File metadata and controls
47 lines (40 loc) · 1.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
40
41
42
43
44
45
46
47
#!/usr/bin/python
# Author= Timo Fischer
import sys
from File import File
from JsonFile import JsonFile
class CsvFile(File):
"""
CSV File Class
"""
def __init__(self, file):
"""
CsvFile class constructor
:param file:
"""
super().__init__(file)
# check if file exists and has correct format
if self.checkFile():
if not self.checkFileType():
sys.stderr.write('File has to be in csv format!')
sys.exit()
def parseContent(self):
"""
parse csv content
get file content and create dict
:return:
"""
lines = self.getContent()
lines = lines.split('\n')
column_header = lines[0]
column_header = column_header.split(';')
array = []
for index, line in enumerate(lines):
if index == 0:
continue
columns = line.split(';')
tmp = {}
for i, value in enumerate(columns):
tmp[column_header[i]] = value
array.append(tmp)
return array