Index out of range error on code builder

OS Win10:
PsychoPy version 2023.2.1:
*Standard Standalone
What are you trying to achieve?:
Screen images from a specific folder, one at a time for a BDM auction.

Here is the code:

**before exp:**
from numpy.random import choice
image_list = list(choice(40, 40, replace = False))
idx = 0

**begin routine:**
import glob
curr_image = glob.glob("BDM Database/*")[image_list[idx]]
thisExp.addData('image', curr_image.split('/')[-1])
idx += 1

Here is the error:

 File "C:\Users\Adi\OneDrive - mail.tau.ac.il\\u05de\u05e1\u05de\u05db\u05d9\u05dd\\u05ea\u05d5\u05d0\u05e8 \u05e9\u05e0\u05d9\CAT Memory\BDM_lastrun.py", line 1091, in <module>
    run(
  File "C:\Users\Adi\OneDri5de\u05db\u05d9\u05dd\\u05ea\u05d5\u05d0\u05e8 \u05e9\u05e0\u05d9\CAT Memory\BDM_lastrun.py", line 760, in run
    curr_image = glob.glob("BDM Database/*")[image_list[idx]]
IndexError: list index out of range
################ Experiment ended with exit code 1 [pid:26580] #################
157.1598     INFO     Loaded monitor calibration from ['2023_09_05 16:25']ve - mail.tau.ac.il\\u05de\u05e1\u0

Thanks ahead :slightly_smiling_face:

Hello

in cases like this, I use a couple of print-commands to check the variable-values. So a

print[idx]
print[image_list[idx]
print(curr_image)

should allow you inspect the values of these three variables.

By the way, are you planning to run the experiment online? If so, do not import any Python libraries. The builder imports all Python libraries that have JavaScript equivalents. Also, do not use a cloud drive to synchronise your experiments with Pavlovia. Cloud drives and Pavlova aka gitlab do not work well together.

Best wishes Jens

1 Like