<p>嗨,伙计们,我想能够通过一个单词列表进入for循环,我如何才能使下面的代码工作</p>
<pre><code>list = ['word1','word2','word3']
for x in list
with open('folder/{x}.txt') as fin:
do something()
</code></pre>
<p>你少了一个冒号。<code>with</code>子句也需要一些工作。下面是如何修复<code>for</code>循环末尾的冒号部分:</p>
<pre><code>list = ['word1','word2','word3']
for x in list:
print(x)
</code></pre>