次の出力を取得するコードに問題があります。
トレースバック (最新の最後の呼び出し): ws1.cell(column=1, row=i, value="%s" % blue_student_list[i])
内のファイル "1stHour.py"、48行目 IndexError: リスト インデックスが範囲外です`
# 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
何かを忘れているか、コードの一部に書き込んでいるような気がします。