<p>我有以下pygame代码,但它通常适用于python</p>
<pre><code>expl_sounds = []
for snd in ['expl3.wav', 'expl6.wav']:
expl_sounds.append(pygame.mixer.Sound(path.join(snd_dir, snd)))
</code></pre>
<p>我想单独禁用列表中的所有项,而不是禁用整个应用程序或混合器。我尝试了以下方法:</p>
<pre><code> for i in expl_sounds:
expl_sounds[i].set_volume(Sound_Volume)
TypeError: list indices must be integers or slices, not Sound
</code></pre>
<p>我没有收到错误信息。循环中的i是一个整数,mixer.set_Volume是元素的有效操作</p>
<p>迭代并将卷应用于每个元素的正确方法是什么</p>
<p>当您编写<code>for i in expl_sounds:</code>时,您正在迭代<code>expl_sounds</code>中的元素,因此您只需执行以下操作:</p>
<pre><code>for i in expl_sounds:
i.set_volume(Sound_Volume)
</code></pre>