Python,从Excel中拉取语句的循环

我仍然是新的python。 只是想知道是否有一个更简单的方法来完成我的任务。

这是我现在的代码

win = visual.Window([800,800],monitor="testmonitor", units="deg") msg = visual.TextStim(win, text='hello this is a test',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) msg = visual.TextStim(win, text='statement 1',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) msg = visual.TextStim(win, text='statement 2',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) msg = visual.TextStim(win, text='statement 3',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2) 

有没有办法从excel文件中提取语句?

例如:我将有一个循环继续进行,每一轮它将拉动文件中的下一行,而不是必须复制代码,并每次写一个新的语句?

D on't
重复
我们自己

你的解决scheme使用4行代码,每行4行,最后3行是一样的,第一个也差不多了!

正如你所猜测的,你可以通过循环来避免这种情况。

查看每个块之间的变化,并将其存储在一个元组中(例如)。 然后,遍历这个元组,并将该块应用于可变元素。

 texts = ( 'hello this is a test', 'statement 1', 'statement 2', 'statement 3' ) for text in texts: msg = visual.TextStim(win, text=text, pos=[0, +1], color='white') msg.draw() win.flip() core.wait(2)