我创建了一个虚拟助手之前播放的音乐,在我安装了一个 api “zolframalpha”之后,播放音乐时发生错误我附上了错误代码错误是:line 1 :-----File "C:\Users\Hari Prakash\Desktop\siri\main.py", line 62, in playMusic os.startfile(location+musics[0]) line2:--------- FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\Hari Prakash\\Desktop\\siri\\musics//wolframalpha.cpython-37.pyc' def playMusic(self): self.speak('Playing Music Please Wait') musics = [x for x in os.walk(os.getcwd())][-1][-1] shuffle(musics) location = os.path.join( os.getcwd(), "musics//" ) os.startfile(location+musics[0]) print(musics) self.main()
1 回答
波斯汪
TA贡献1811条经验 获得超4个赞
线
musics = [x for x in os.walk(os.getcwd())][-1][-1]
获取当前工作目录中最后一个子目录中的文件列表
假设您的音乐位于当前工作目录的“musics”文件夹中,您可以像这样重新排序代码并将行更改为musics =
def playMusic(self):
self.speak('Playing Music Please Wait')
location = os.path.join(
os.getcwd(),
"musics//"
)
# get all files in musics location
musics = [x for x in os.listdir(location) if os.path.isfile(location + x)]
shuffle(musics)
os.startfile(location+musics[0])
print(musics)
self.main()
添加回答
举报
0/150
提交
取消