| Reference | Downloads | Github

Randomly selecting different sheets in excel file for conditions

Hi all!

I’m trying to randomly select different conditions for the conditions under trials property. So I had $SheetSelect under the condition in builder.

I am able to randomly select a different excel file using this code below, it works.

myWB = [‘condition1.xlsx’,‘condition2.xlsx’,‘condition3.xlsx’]
import random
SheetSelect = random.choice(myWB)

Now, what if condition1 is in sheet1 of Conditions.xlsx; condition2 is in sheet2 of Conditions.xlsx and etc. I have tried the following code, and it doesn’t work, it got stuck at data.importCondition

import random
myWB = 'Conditions.xlsx’
mySheet = [‘myWB.Sheet1’, ‘myWB.Sheet2, ‘myWB.Sheet3’’]
SheetSelect = random.choice(mySheet)

Is there any way to do this?


Hi Shirley, the data.importCondtions() function only works with filenames (for .csv or Excel files). It can’t burrow down into individual sheets within an Excel file.

i.e. you’ll need to split your Excel file into one file per sheet.