Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 列表中的格式化字符串_String_List_Psychopy_Formatted - Fatal编程技术网

String 列表中的格式化字符串

String 列表中的格式化字符串,string,list,psychopy,formatted,String,List,Psychopy,Formatted,我的任务是多对象跟踪任务的变体。屏幕上有7个圆圈。它随机选择3个圆圈来短暂改变颜色(红色、绿色、蓝色),以指示参与者跟踪这些圆圈。颜色更改后,所有圆将更改为相同的颜色,并且这些圆将移动一段时间。当圆圈停止移动时,将出现响应提示,参与者将从三个彩色圆圈中选择一个(“选择红色/绿色/蓝色圆圈”)。我很难在格式化字符串中插入要选择的颜色圈。我一直收到错误消息:不支持%的操作数类型:'textsim'和'list' 我不知道我是否需要或如何转换这些列表,所以任何帮助将不胜感激 n_targets = 7

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

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

ResponsePrompt = visual.TextStim(win, text = "Select the %s circle") %TrialTarget
i、 e.
responseCompt
显然是一个visual.TextStim,因为您将它作为一个整体创建,我认为
TrialTarget
是一个visual.Circle刺激,因为您从一个圆圈列表中随机采样它

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

ResponsePrompt = visual.TextStim(win, text = "Select the %s circle" % trialColour)
i、 e.此处的
TrialColor
实际上是一个字符串,格式化操作放在括号内,因此它直接应用于文本字符串
“选择%s圆圈”


这将有望解决你眼前的问题。您可能还想研究使用
random.shuffle()
来替换
random.sample()

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

ResponsePrompt = visual.TextStim(win, text = "Select the %s circle") %TrialTarget
i、 e.
responseCompt
显然是一个visual.TextStim,因为您将它作为一个整体创建,我认为
TrialTarget
是一个visual.Circle刺激,因为您从一个圆圈列表中随机采样它

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

ResponsePrompt = visual.TextStim(win, text = "Select the %s circle" % trialColour)
i、 e.此处的
TrialColor
实际上是一个字符串,格式化操作放在括号内,因此它直接应用于文本字符串
“选择%s圆圈”


这将有望解决你眼前的问题。您可能还想研究使用
random.shuffle()
来替换
random.sample()(但当您想运行时也要删除它们-大量的print语句可能会在一段时间后导致崩溃)如果怀疑存在类型错误,可以随意添加一些调试语句,如
print(type(TrialTarget))
(但当您想运行时也要删除它们-大量的print语句可能会在一段时间后导致崩溃)