Problem
i use the following code to read a file and manipulate it. I reuse the first bit of my code for every function to add the data into two files. however the last function does not add data to my list even though it is exactly the identical code? it does not even print the lines of the file?
data_laag = open('/Users/arkin/programming/TN_STAID000162.txt')
data_hoog = open('/Users/arkin/programming/TX_STAID000162.txt')
def temp_laag(data):
temp = []
date = []
line_num = 0
for line in data_laag:
if line_num < 22:
line_num += 1
else:
data = line.split(',')
temp.append(float(data[3])/10)
date.append(data[2])
min_temp = 999
for i in temp:
if i < min_temp:
min_temp = i
index = temp.index(min_temp)
print 'De minimum temperatuur ooit gemeten is:' ,min_temp, 'Dit was op de volgende datum', date[index][:4],date[index][4:6],date[index][6:8]
temp_laag(data_laag)
def temp_hoog(data):
temp = []
datum = []
line_num = 0
for line in data_hoog:
if line_num < 22:
line_num += 1
else:
data = line.split(',')
temp.append(float(data[3])/10)
datum.append(data[2])
max_temp = 0
for i in temp:
if i > max_temp:
max_temp = i
index = temp.index(max_temp)
print 'De maximum temperatuur gemeten is', max_temp , 'Dit gebeurd op op de volgende datum', datum[index][:4],datum[index][4:6],datum[index][6:8]
temp_hoog(data_hoog)
def aantal_dagen(data):
temp = []
date = []
line_num = 0
for line in data:
print line
if line_num < 22:
line_num += 1
else:
data = line.split(',')
temp.append(float(data[3])/10)
date.append(data[2])
print temp
aantal_dagen(data_laag)
data_laagso reading it a second time will return nothingdata_biig = open('/Users/arkin/programming/TX_STAID000162.txt')then callaantal_dagen(data_biig).readlinesto read into memory or usefile.seek(0)to go back to the start each time