I have a CSV file of dates and a float (day,month,year,float). here is sample,
1,1,2000,4076.79
2,1,2000,1216.82
3,1,2000,1299.68
4,1,2000,637.36
5,1,2000,3877.91
6,1,2000,3308.99
7,1,2000,2925.93
8,1,2000,1559.09
9,1,2000,3190.81
10,1,2000,3008.66
11,1,2000,2026.35
12,1,2000,3279.61
13,1,2000,3601.6
14,1,2000,2021.1
15,1,2000,2103.62
16,1,2000,609.64
17,1,2000,633.16
18,1,2000,1195.34
I want to read the first line then the last one:
handle = open(getInputFileName(), "r")
getInputFileName() obv. is a function that return file name. then,
print "numberlines", numberLines #DEBUG#
>>> 3660
numberLines is the number of lines in file. then,
handle.seek(0)
lineData = handle.readline().split(",")
print lineData #DEBUG#
>>> ['1','1','2000','4076.79\n']
until here everything works just fine. but then,
handle.seek(numberLines-1)
lineData = handle.readline().split(",")
print lineData #DEBUG#
>>>['7', '7', '2000', '2347.51\n']
but in fact the last line in file is 31,12,2009,3823.02
why isnt seek going all the way down?
i tried deleting the line that it gets stuck at but then the program crashed ValueError: could not convert string to float:
(I then use lineData as float):
newestDate.insert(1,float(lineData[1]))
I checked the file if there was a problem with lines but the format never changes. how come does my code work for the first line but not the last?