psychopy.org | Reference | Downloads | Github

Using code to pick a random list

Hello,

I am trying to use a code to choose 1 of 4 condition lists I have. Currently I keep getting the error:
Traceback (most recent call last):
trialList=data.importConditions(Lists),
fieldName = fieldNames[colN]
IndexError: list index out of range

currently I have a block of code before the loop with this in “begin experiment”
pickfile = “.”

randnum = randint(1,4)

if randnum == 1 :
pickfile = ‘L1B1PTNW.xlsx’
elif randnum == 2 :
pickfile = ‘L2B1PTNW.xlsx’
elif randnum == 3 :
pickfile = ‘L3B1PTNW.xlsx’
else :
pickfile = ‘L4B1PTNW.xlsx’

Then I have two loops. The outer loop is called List Pick because I have conditions set to an excel file ‘Call_Lists.xlsx’, which contains the names of all the condition files under the column heading ‘Lists’. On the inner loop, conditions calls $Lists. The end Code block just ends the loop.

You’ve said that you’re using $Lists but your code sets pickfile?

Yes, I was trying to have pickfile be filled with a random number and assign each conditions file a number. 1, 2, 3, or 4, then have those conditions in a larger excel file under the column header “lists”. So, the outer loop calls the excel file ‘callListsB1PTNW.xlsx’ with all the condition files in it and the inner loop calls $Lists. I am a novice coder. Should one of the loops be calling pickfile?
callListsB1PTNW.xlsx (9.7 KB)

If you want each participant to see just one list then delete your outer loop and set the inner loop to $pickfile

If you want each participant to see all four lists in a random order delete your pickfile code and set the inner loop to $fileName. In the spreadsheet you just attached Lists doesn’t have the file extension.

I want each participant to see just one list. So, I deleted the outerloop and set the inner loop to $pickfile and it crashed and I got this error message:
Traceback (most recent call last):
File “C:\Users\sadie\Desktop\S2 Pre-Test Oddity (B01V1NF)\S2PreTOddityNF_lastrun.py”, line 1767, in
trialList=data.importConditions(pickfile),
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\utils.py”, line 420, in importConditions
fieldName = fieldNames[colN]
IndexError: list index out of range

Do you have any code mentioning colN in your experiment?

No, I wasn’t sure what that stood for, but no matter how I change the code to different suggestions I’ve found on boards, it gives me that same error messafe using that ‘coIN’.

Maybe there’s an issue with your spreadsheets – like the cursor being in a column without a header

I checked the cursor in them all and there’s no issue. I thought maybe it wasn’t saving code changes since it seems to be pulling from lastrun? But I have tried all of the suggestions for making sure that’s not the problem either. Is there anything else I should check for in thet condition files. I’ll attach one of them. Thank you for your hlep! L1B1PTNW.xlsx (12.9 KB)

Traceback (most recent call last):
File “C:\Users\sadie\Desktop\S2 Pre-Test Oddity (B01V1NF)\S2PreTOddityNF_lastrun.py”, line 1764, in
trialList=data.importConditions(pickfile),
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\utils.py”, line 420, in importConditions
fieldName = fieldNames[colN]
IndexError: list index out of range

Do you have a valid value for nReps in your loops?

I have nReps sets to 1