URL of experiment: none yet
Description of the problem:
Dear code wizards,
I am trying to upload an experiment to Pavlovia that I have partly created in PsychoPy builder, but that includes some code components. I have amended some of my code according to the Wake crib sheet, but I am stuck on one particular piece of code: the import XLRD.
A bit of background: xlrd is used in a lot of python tutorials to create a big dataframe from a csv and typically looks like this:
import xlrd
infile = “file_name.xlsx”
workbook = xlrd.open_workbook(infile)
sheet = workbook.sheet_by_index(0)
With the “sheet”, you can create arrays like so:
stim_list = #creates an empty array
for rowx in range (list_start, list_end):
row = sheet.row_values(rowx)
stim_list.append(row[0]) #here, the first column of the “sheet” is appended to an empty array for every row in the specified range
Here is the problem though. I can’t use import functions in Pavlovia. I’ve looked around and found this piece of JS code that supposedly creates a master dictionary similar to the csv “sheet” described above.
expVars = {};
csvData = data.importConditions(‘stims.csv’);
for k in csvData[0]:
expVars[k] = [d[k] for d in csvData];
( I can access the dictionary like this: >expVars[‘var1’][33])
Moving on, I want to create arrays from this dictionary file. I still use the append function, but have added a piece of code at the beginning of my experiment that translates it the JS equivalent:
Array.prototype.append = .push;
I’ve also done the same for the range function
range = function (size, startAt = 0) {
return […Array(size).keys()].map(i => i + startAt);
}
Finally, my code looks like this:
expVars = ;
csvData = data.importConditions(‘stims.csv’);
for k in csvData[0]:
expVars[k] = [d[k] for d in csvData];
stim_list =
for rowx in range (list_start, list_end):
row = expVars.row_values(rowx)
stim_list.append(row[0])
When I upload this, the experiment is stuck on initialising. I suspect that the problem lies somewhere with the loop that creates the stim_list array, but I’m not sure and I don’t know how to fix this.
Any help would be greatly appreciated. I am new to all of this, so please use short words ^^.