Well I’m going to back track and give you an implementation of @Michael 's suggestion, because I think it’s a good one, and you should learn how to do stuff like this.
Here’s some code to create a folder called “stimLists”, and create 36 spreadsheets with a column named “imPath” in each, and instead of actual paths, the rows are numbers 1-1, 1-2, 1-3 … etc. for list 1, 2-1, 2-2, 2-3 … etc. for list 2, etc. This won’t be helpful for your final implementation, but it lets us quickly write some test code to make sure these steps work.
import os
targetDir = "stimLists"
os.mkdir(targetDir)
for i in range(1, 37):
outFil = os.path.join(targetDir, u"list" + unicode(i) + ".csv")
with open(outFil, "w") as f:
f.write("imPath\n")
for j in range(1, 37):
f.write(unicode(i) + u"-" + unicode(j) + "\n")
Now for the real script that open each of these 36 files, randomly selects one line, puts it in a list, then shuffles this list.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from psychopy import data
from glob import glob
# don't want to interfere with numpy's random,
# so importing random under a different name, just in case
import random as rnd
# folder containing spreadsheets
spreadPath = u"stimLists"
# Extention of spreadsheets, You would use this for your excel sheets
#spreadExt = u".xlsx"
spreadExt = u".csv"
spreadsheets = glob(spreadPath + "/*" + spreadExt)
chosenImages = []
for ss in spreadsheets:
sData = data.importConditions(ss)
# choose one conditions file line at random
rl = rnd.choice(sData)
chosenImages.append(rl)
# now mix up the chosenImages
rnd.shuffle(chosenImages)
# print them out to have a look and see that
# it's working.
for ci in chosenImages:
print(ci)
## You should be able to give "chosenImages" to a trial handler
As a side note, I would include a column with a unique label for each line like the one here (24-2 = spreadsheet 24, item 2), since it will help make sense of data later, if you aren’t doing so already.
Again, sorry I’m not answering your latest question, but if it were me I might try a solution like this. But as to that error, I’m not sure what it might be, but the issue is frequently an excel sheet with some “noise”, like extra rows, or left over cruft from editing of excel files. @Michael is right about .csv files being easier to manipulate in code. If you decide to go the route you last suggested, my first step would be to see if the problem still exists with a single fresh spreadsheet.