I’m coding my first experiment in PsychoPy. I’m using TrialHandler to control the stimuli and save the data, but when I try to output the data, I get the error “TypeError: argument of type ‘int’ is not iterable”. Can someone please point out what I am doing wrong?
Note: I get the same error no matter which text mode I use to output the data: saveAsText, printAsText, or saveAsWideText.
from __future__ import division
from __future__ import print_function
from builtins import range
from psychopy import core, visual, gui, data, event
from psychopy.tools.filetools import fromFile, toFile
import numpy, random # standard python libraries
# list default parameters here
windowSize = [400, 400]
fixationSeconds = 0.5
stimulusSeconds = .5
trialsPerCell = 2
# insert data saving information here
outputFile = 'gistWide.txt'
# create window and stimuli
win = visual.Window(windowSize, allowGUI = True, monitor = 'testMonitor', units = 'deg')
fps = win.getActualFrameRate()
print(fps)
fixationFrames = int(fps*fixationSeconds)
print(fixationFrames)
stimulusFrames = int(fps*stimulusSeconds)
print(stimulusFrames)
fixation = visual.TextStim(win, pos = [0,0], text = '+')
postStimulus= visual.ImageStim(win, image = 'anatomy1.png')
# setup trial handler
abnormal = [0,1] # 0 = normal, 1 = abnormal
trials = data.TrialHandler(abnormal, trialsPerCell, method = "fullRandom")
trials.data.addDataType('accuracy')
trials.data.addDataType('RT')
clockRT = core.Clock() # initialize reaction times
for thisTrial in trials:
# present a single cycle
stimulus = visual.ImageStim(win, image = 'prostate1.png')
for f in range(fixationFrames):
fixation.draw()
win.flip()
for f in range(stimulusFrames):
stimulus.draw()
win.flip()
postStimulus.draw()
win.flip()
clockRT.reset()
# collect response
# let's say "z" is for abnormal/present and "/" is for normal/absent
accuracy = None
while accuracy == None:
allKeys = event.waitKeys(timeStamped = clockRT)
for keyTuple in allKeys:
[thisKey, thisRT] = keyTuple
print(thisKey)
print(trials.thisTrial)
if thisKey == 'z':
if trials.thisTrial == 1: accuracy = 1
else: accuracy = 0
elif thisKey == 'slash':
if trials.thisTrial == 1: accuracy = 0
else: accuracy = 1
elif thisKey in ['q', 'escape']:
core.quit()
event.clearEvents()
trials.addData('accuracy', accuracy)
trials.addData('RT', thisRT)
df = trials.saveAsWideText(fileName = outputFile)
core.quit()