Код: Выделить всё
IndexError: list index out of rangeЧто я упускаю или делаю неправильно?
КОД PYTHON:
Код: Выделить всё
import csv
import os
os.chdir("My Personal Path located on my computer")
times = ["09:00 - 11:00", "11:00 - 13:00", "13:00 - 15:00", "15:00 - 17:00", "17:00 - 19:00",
"19:00 - 21:00", "21:00 - 23:00"]
day = input("Wich day?\n")
print("\n")
print(*times, sep = "\n")
time = input("\nWich time? Choose one of above.\n")
#open CSV file
csvfile = open("planning.csv", mode="r", encoding="ISO-8859-1")
data = csv.reader(csvfile)
data = [row for row in data]
if day == "1" and time == "09:00 - 11:00":
#grab one record data [row][col]
person1 = str(data[5][3])
elif day == "1" and time == "11:00 - 13:00":
#grab one record data [row][col]
person1 = data[6][3]
elif day == "1" and time == "13:00 - 15:00":
#grab one record data [row][col]
person1 = data[7][3]
elif day == "1" and time == "15:00 - 17:00":
#grab one record data [row][col]
person1 = data[8][3]
elif day == "1" and time == "17:00 - 19:00":
#grab one record data [row][col]
person1 = data[9][3]
if person1 =="x":
c_person1 = "Yes"
else:
c_person1 = "No"
print("Person1: " + c_person1)
Код: Выделить всё
File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\finn\untitled0.py:29
person1 = str(data[5][3])
IndexError: list index out of range
Вот скриншот документа csv:
ss csv doc
Подробнее здесь: https://stackoverflow.com/questions/787 ... r-csv-data