Program crashes with "IndexError: list index out of range" after running through a loop twice (but not after running through it only once)

If this template helps then use it. If not then just delete and start from scratch.

OS (Win11):
PsychoPy version (v 2026.2.2.):
Standard Standalone Installation? y
Do you want it to also run online? n

What are you trying to achieve?

Run a loop twice, then continue with the rest of the experiment.

What did you try to make it work?:

The loop contains a sequence of 4 trials. Each line in the conditions file (“CongrPract.csv”) specifies the parameters for each of the four trials (Congr1, Arrow1, XPos1, YPos1, CorrAns1, Congr2, Arrow2… etc. until CorrAns4). The conditions file contains four of these lines, thus, running through the loop once creates 16 trials for the participant, running through the loop twice creates 32 trials, and so on.

The loop is set to FullRandom, and IsTrials is selected.

Loop:

Conditions file:

What specifically went wrong when you tried that?:
When I set Num. Repeats to 1, the experiment runs perfectly: the loop completes and the program moves on to the next component (“FeedbackPract”).

However, when I set Num. Repeats to 2, the experiment crashes AFTER it has completed the loop twice, but before it reaches the next component.

The full list of warnings and error messages is

Traceback (most recent call last):
17.0975 WARNING psychopy.parallel has been imported but no parallel port driver found. Install either inpout32, inpoutx64 or dlportio
File “C:\Users\pssdb\OneDrive\Simon8Alt.py”, line 10690, in
run(
File “C:\Users\pssdb\OneDrive\Simon8Alt.py”, line 3346, in run
Pract1.saveAsExcel(filename + ‘.xlsx’, sheetName=‘Pract1’,
File “C:\Users\pssdb\OneDrive\PsychoPy\lib\site-packages\psychopy\data\base.py”, line 324, in saveAsExcel
dataArray = self._createOutputArray(stimOut=stimOut,
File “C:\Users\pssdb\OneDrive\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 1496, in _createOutputArray
thisLine.append(self.trialList[stimN][heading])
IndexError: list index out of range
20.0511 WARNING User requested fullscreen with size [1680 1050], but screen is actually [1920, 1080]. Using actual size
######## Experiment ended with exit code 1 [pid:30012] #########

Because this suggested that the problem is with the “saveAsExcel” command, I deselected “Save excel file” from the experiment parameters. Unfortunately, this made no difference: the program still crashed after running through the loop twice, the error message was still “IndexError: list index out of range”.

Any help would be greatly appreciated!

Thanks,

Friederike

Links to posts reporting similar problems:

Experiment Index Error : list index out of range - Builder - PsychoPy

Do you have these settings?

One workaround, since you want full random, is to copy the lines so your spreadsheet has 8 rows instead of 4.

Also, make sure you don’t have any relevant Excel files open when running.

I’m not sure what might be causing the error, so I’m just trying to imagine things that could affect it.

Using these settings (i.e., deselecting both “save excel” and “save csv summaries”) actually solves the problem - thank you!!

It still seems rather weird, though: I mean, the whole point of a loop is to run it repeatedly, and in all of my other experiments, I can do so while saving any kind of file. If anybody has any idea about the underlying problem, I’d be really interested to hear about it.

My best guess, which I haven’t managed to replicate, is that it is related to having multiple routines within the loop when creating the summary.

If I have two copies of a trial routine within a loop then the summary seems to only show the keyboard response for the second one. If I have two routines with different names (and therefore different keyboard component names) then I get both responses.