【问题标题】:Formatted String from List Psychopy来自 List Psychopy 的格式化字符串
【发布时间】:2015-11-10 02:31:36
【问题描述】:

我的任务是多对象跟踪任务的变体。屏幕上有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

【问题讨论】:

  • 如果对类型错误有疑问,请随意添加一些调试语句,例如print(type(TrialTarget))
  • (但在你想运行时也将它们删除 - 大量打印语句可能会在一段时间后导致崩溃)

标签: string list psychopy formatted


【解决方案1】:

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

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

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

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

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

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

这有望解决您当前的问题。您可能还想调查使用random.shuffle() 来随机播放列表而不是random.sample()

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多