我正在编写一个Stroop任务来做精神病实验。我试图绘制图像和文本刺激,但我得到了错误消息(如下所示)。在
我试过查看google/stackoverflow页面,但是不理解这个错误消息(所以很难修复这个代码)。在
# ------Prepare to start Routine "instructions"-------
t = 0
instructionsClock.reset() # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
ready = event.BuilderKeyResponse()
# keep track of which components have finished
instructionsComponents = [instrText, ready]
for thisComponent in instructionsComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#read stimuli file
trials = open('cog2.csv', 'rb')
imageFile = 0 #imageFile = trials[trialNumber][Column]
corrAns = 1 #corrAns = trials[trialNumber][Column]
Congruent = 2 #Congruent = trials[trialNumber][Column]
stimCat = 3 #stimCat = trials[trialNumber][Column]
Superimposed = 4 #Superimposed = trials[trialNumber][Column]
Word = 5 #word = trials[trialNumber][Column]
#turn the text string into stimuli
textStimuli = []
imageStimuli = []
for trial in trials:
textStimuli.append(visual.TextStim(win, text=trials[Word])) <---- ERROR
imageStimuli.append(visual.ImageStim(win, size=[0.5, 0.5], image=trials[imageFile]))
我试着从我上传的excel文档(包含jpg图片的路径,以及我想在图片上叠加的单词)写出draw刺激。在
但目前,我收到了错误消息:
^{pr2}$
trials
变量是一个file对象(来自trials = open('cog2.csv', 'rb')
),您试图用trials[Word]
作为列表访问它,因此出现错误。在您应该使用
csv.reader
方法以CSV的形式读取文件,这样trial
将作为一个列表分配给每一行,并且您可以按照您的预期使用索引访问每个列:相关问题 更多 >
编程相关推荐