Change
times=open("E:\\Python\Copyofresttable.csv","r")
to:
times=open("E:\\Python\Copyofresttable.csv","r").read()
in your first line and add a
print('#Times: {0}'.format(len(times.split())))
to make sure you have enough lines...
Update:
You traceback (in comment) shows that your (1st?!) dayoftheweek
seems to be a wednesday, that's why your 1st two ifs are ignored. Then it seems like your list a
doesn't have nough entries.
You may check that assumption with a print("# a: {0}".format(len(a)))
So if you have less then 3 entries a[2]==
must fail because the list index out of range
;-)
Ahh, i didn't read your question properly at first. And it makes more sense that way, if every 1st if-statement is throwing an exception....
Update 2:
Btw: You should rearange your for line in times:
loops to a less redundant way, like:
lines=open("E:\\Python\Copyofresttable.csv","r").readlines()
...
for line in lines:
a = line.split(',')
if a[2] == "Monday" == dayoftheweek:
...
elif a[2] == "Tuesday" == dayoftheweek:
...
elif a[1]== "Iron Hill" and a[2] =="Wednesday" == dayoftheweek:
...
Update 3:
You could "cheat" a little if ommiting some lines, by doing something like:
a = line.split(',')
if len(a) < 6:
continue # ignores the rest of the loop and jumps stright to the next iteration