| Reference | Downloads | Github

Keyboard.corr unexpected behavior

OS (e.g. Win10): Independent
PsychoPy version (e.g. 1.84.x): 1.84.5
Standard Standalone? (y/n) Independent
What are you trying to achieve?: Have the correct answer recognized

What did you try to make it work?: The code here

What specifically went wrong when you tried that?:
All the responses were recorded, but the keyboard.corr is always zero even if ans and the keyboard.keys entries display the same number (e.g. 2), meaning the trial was completed correctly.


The underlying issue is that the events_rt.csv file has a column named ans, that wholly consists of numbers, and when they are read into the program, they are interpreted as floats such that when this line of code is executed:
if (keyboard.keys == str(ans)) or (keyboard.keys == ans):
if ans was written as 2, it’s interpreted as 2.0, and if a key press is a string, such as '2', the tranformation str(ans) is str(2.0) which results in '2.0', not 2.

Is there a more general solution to this besides going in the code and changing
if (keyboard.keys == str(ans)) or (keyboard.keys == ans):
if (keyboard.keys == str(int(ans))) or (keyboard.keys == ans):

idk if it would be beneficial to automatically read in whole numbers from a csv as an integer instead of a float, and resort to float interpretation if there is a decimal in the csv.

Now I see the deeper issue, psychopy uses pandas to load in a csv, which can’t support integer NaNs.

So then the workaround could be:
giving null trials a keypress solution that would never be pressed.

I’m still stuck in an eprime mode of thought where a goto statement could jump either to the trial or to a null. Python doesn’t have goto, but is there a recommended way to achieve such behavior?


1 Like