-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvTools.py
More file actions
52 lines (43 loc) · 1.1 KB
/
csvTools.py
File metadata and controls
52 lines (43 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
48
49
50
51
52
'''
provided by LUNA16
evaluation script
'''
import csv
import platform
def writeTXT(filename, lines):
with open(filename, 'w') as f:
for line in lines:
f.write(line+'\n')
def writeCSV(filename, lines):
if 'Darwin' in platform.system():
with open(filename, "wb") as f:
csvwriter = csv.writer(f)
csvwriter.writerows(lines)
else:
with open(filename, "w", newline='') as f:
csvwriter = csv.writer(f)
csvwriter.writerows(lines)
def readCSV(filename):
lines = []
with open(filename, "r") as f:
csvreader = csv.reader(f)
for line in csvreader:
lines.append(line)
return lines
def tryFloat(value):
try:
value = float(value)
except:
value = value
return value
def getColumn(lines, columnid, elementType=''):
column = []
for line in lines:
try:
value = line[columnid]
except:
continue
if elementType == 'float':
value = tryFloat(value)
column.append(value)
return column