実行時にランダムなwavファイルを再生するプログラムがあります。私はプログラムを実行するときしかし、私はこのエラーを取得する:PygameはRaspberry Piの曲を開くことができません
Traceback (most recent call last):
File "pi/home/python_music/music.py", line 19, in <module>
pygame.mixer.music.load(song)
error: Couldn't open 'Song1.wav
'
は、これはコードです:
import pygame
import random
f = open('List.txt', 'r+')
songs = []
while True:
x = f.readline()
if x == '':
break
songs.append(x)
f.close()
while True:
y = randint(0, len(songs))
song = songs[y]
pygame.mixer.init()
pygame.mixer.music.load(song)
pygame.mixer.music.play()
while True:
if pygame.mixer.music.get_busy()== False:
pygame.mixer.quit()
break
とlist.txtには、次のようになります。
Song1.wav
Song2.wav
Song3.wav
.
.
.
Song12.wav
プログラムが実行されますRaspbianのRaspberry Piで、Pygameを使って このエラーはなぜ発生しますか?
'songs.append(x)'のような縫い目は決して届かず、それは問題の可能性があります – juanjo