-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfourth
53 lines (42 loc) · 1.38 KB
/
fourth
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
53
# refactor to make more flexible, less hard to change
# add a new key with making changes throughout file
# Column names and column indices to read
columns = {'date':0, 'time':1, 'tempout':2}
# data types for each column
# float is a function pointer here, not a function
type = {'tempout': float}
# initialize data variable
# a dicionary, will populate later
# init each list to empty
data = {}
for column in columns:
# empty list
data[column] = []
filename = "data/wxobs20170821.txt"
with open(filename, 'r') as datafile:
# orig data = datafile.read()
# read the first 3 lines (header)
# v a place holder variable (instead of i, j ...) indicates we'll never use the variable
for _ in range(3):
# could have said 'for i in [0,3]'
# print(_)
datafile.readline()
# Read and parse the rest of the file
# each line is a string
for line in datafile:
# split along white space
split_line = line.split()
# add datum to the list 'data'
for column in columns:
i = columns[column]
# there's only one of these
t = type.get(column, str)
value = t(split_line[i])
data[column].append(value)
# Some kind debugging or what it would try to do
# d.get(key, str)
# d['key'] --- > str
print(data['tempout'])
# Debug
# print(data['tempout'])
# % git log --oneline