1

我的任务是多对象跟踪任务的变体。屏幕上有7个圆圈。它随机选择 3 个圆圈来短暂更改颜色(红色、绿色、蓝色),以指示参与者跟踪这些圆圈。颜色改变后,所有的圆圈都会变成相同的颜色,圆圈会移动一段时间。当圆圈停止移动时,将出现响应提示,参与者将选择三个彩色圆圈之一(“选择红色/绿色/蓝色圆圈”)。我很难将要选择的色环插入格式化字符串。我不断收到错误消息:%: 'TextStim' 和 'list' 不支持的操作数类型

我不确定我是否需要或如何转换这些列表,所以任何帮助将不胜感激!

n_targets = 7 #seven locations     
circles = [] #setting up the circle stimuli
for i in range(n_targets):
    tmp = visual.Circle(win,radius = 27,units = 'pix',edges = 32,fillColor='white',lineColor = 'black',lineWidth = 1, pos=(posx[i],posy[i]))
circles.append(tmp)
cols = ['blue','red','green'] #3 colors the circles will change to 
targets = random.sample(circles,3) #randomly select 3 of the 7 circles
TrialTarget = random.sample(targets, 1) #select 1 of the 3 circles to be the target for the trial 
#code for movement would go here (skipping since it is not relevant)
#at end of trial, response prompt appears and ask user to select target and is where error occurs
ResponsePrompt = visual.TextStim(win, text = "Select the %s circle") %TrialTarget
4

1 回答 1

0

在这一行中,您尝试从 TextStim 对象和 Circle 刺激对象而不是字符串对象和另一个字符串对象创建格式化字符串:

ResponsePrompt = visual.TextStim(win, text = "Select the %s circle") %TrialTarget

ResponsePrompt显然是一个visual.TextStim,因为你正在创建它,我认为TrialTarget它是一个visual.Circle 刺激,因为你从一个圆圈列表中随机采样它。

我猜您实际上想将颜色标签合并到提示文本中。因此,要解决这两个问题(类型不兼容和格式化语法),您需要实际获取 的元素之一cols,称为 say trialColour,并使用如下内容:

ResponsePrompt = visual.TextStim(win, text = "Select the %s circle" % trialColour)

ie这里trialColour实际上是一个字符串,格式化操作被带入括号内,所以它直接应用于文本字符串"Select the %s circle"

这应该有望解决您的直接问题。您可能还想调查使用random.shuffle()to shuffle list in place 而不是 random.sample().

于 2015-11-10T04:16:14.907 回答