I am trying to have a question from a data table appear in a form
The question is chosen by the random function and there are dozens of questions
def continue_button_show(self, **event_args):
This method is called when the Button is shown on the screen"""
self.my_list = list(app_tables.questions_choice.search())
random.shuffle(self.my_list)
self.index = 0
self.label_14.visible = True
def update_question(self):
row = self.my_list[self.index] # This is line 27
self.label_1.text = row['question_column']
self.label_3.text = row['Column1']
self.label_4.text = row['Column2']
self.label_5.text = row['Column3']
self.label_6.text = row['Column4']
self.label_7.text = row['Column5']
self.label_8.text = row['Column6']
self.label_9.text = row['Column7']
self.label_10.text = row['Column8']
The column from which the questions are being asked has already been accessed earlier in the code and this code is meant to prevent (or at this stage highlite the fact that the random choice has already been used).I then intend writing some code to skip that question and re-run random choice.
def continue_button_click(self, **event_args):
"""This method is called when the button is clicked"""
try:
row = self.my_list[self.index]
q = row['question_index']
self.log_second_answers(q)
self.index +=1
except Exception as e:
print (e)
for row in app_tables.button_capture_from_user.search():
existing_question_numbers = (row["question_number"])
row = self.my_list[self.index]
q = row['question_index']
if q == existing_question_numbers:
print ('found one')
for row in app_tables.button_capture_from_user.search():
existing_question_numbers = (row["question_number"])
if q != existing_question_numbers:
print('ok')
self.update_question_index()
else:
q == existing_question_numbers
print ('found one')
The program runs perfectly for some time and finds the repeated questions then continues perfectly (approximately 4 to 8 cycles)and then this error appears.The error does not appear after a constant amount of questions asked.
This is the eroor that appears
IndexError: list index out of range at [Homeform.questionForm.questionForm_3, line 27](javascript:void(0)) called from [Homeform.questionForm.questionForm_3, line 73](javascript:void(0)) called from [Homeform.questionForm.questionForm_3, line 63](javascript:void(0))