Use an excel column in a code

Hi, all. I’m trying to check an excel file row during my experiment.

I have two rows in the excel file, one for the directory route of each stimulus, the second for the right answer (correct/wrong) with a mouse response. I’m trying to check if the participant’s response was the right answer. I know that with a keyboard there’s the “store correct” option, but not with the mouse.

The code in End routine would look like:

if correct.contains(mouse):
    if "excel file row" == "correct":
        resultats.write('correct ' + str(clock.getTime() - 9) + '\n')
    else:
        resultats.write('wrong ' + str(clock.getTime() - 9) + '\n')
elif wrong.contains(mouse):
    if "excel file row" == "wrong":
        resultats.write('correct ' + str(clock.getTime() - 9) + '\n')
    else:
        resultats.write('wrong ' + str(clock.getTime() - 9) + '\n')
else:
    resultats.write('blank ' + str(clock.getTime() - 9) + '\n')

Thanks to all

  1. I think you are confusing rows with columns.
  2. Your Excel column titles shouldn’t contain spaces
  3. Your Excel column titles shouldn’t be in quotes
  4. Is there a reason why you are creating a bespoke data file instead of using thisExp.addData(‘colName’, dataToSave) ?

I am totally confusing rows with columns, sorry. The quotes and spaces are just for showing where the code for the column should appear.

As for the 4th point, no there is no reason, I actually don’t know how “thisExp.addData” works, I am very new to this… It might be confusing that the two response buttons are called “correct/wrong”, like the two variables in the excel column:

Captura de pantalla 2021-04-26 a les 11.55.48

What error messages, if any, are you getting?

Are you trying to run this online or locally?

Have you looked at the data file automatically generated by PsychoPy to see what you might want to add to it?

I am running it locally and I am not getting any error messages, so far I have the following output file, which is “number_of_trial response_button response_time”. So the “correct/wrong/blank” is the button the participant clicks at, but I would like to check from the excel file column if that answer was right or wrong.

1 correct 0.37624177103862166
2 wrong 4.520120272994973
3 blank 0.3221971980528906
4 blank 2.3760134080657735

I didn’t get any error because I haven’t tried to check the excel column yet…