我在获取以下输出的代码时遇到问题:
回溯(最后一次调用):
文件“1stHour.py”,第 48 行,在
ws1.cell(column=1, row=i, value="%s" % blue_student_list[i])
IndexError: list index out of range `
# coding=utf:8
from pythonzenity import Message
from openpyxl.styles import PatternFill
from openpyxl import Workbook
import bluetooth
import time
def student_check(index):
result = bluetooth.lookup_name(blue_address_list[index], timeout=3)
if (result is not None):
return True
else:
return False
blue_student_list = ['Name', 'Name2']
blue_address_list = ['Address', 'Address2']
redFill = PatternFill(start_color='FF0000', end_color='FF0000', fill_type='solid')
greenFill = PatternFill(start_color='00FF00', end_color='00FF00', fill_type='solid')
for i in range(0, len(blue_address_list)):
i = i + 1
ws1.cell(column=1, row=i, value="%s" % blue_student_list[i])
if (student_check(i)):
ws1.cell(column=2, row=i, value="%s" % "Present").fill = greenFill
else:
ws1.cell(column=2, row=i, value="%s" % "Absent").fill = redFill
Message(title="Attendance Checker",text="You can now open the Excel Document on your Desktop", timeout=3000)
我有这个工作但忘记保存它,所以我没有正确的方法我以前在这里了。我能做些什么来防止这个错误?我觉得我忘记了一些东西或i = i + 1
在我的代码中写了一些东西。