[英]How can I add a list of values to a dictionary where the first element in the list belongs to the first key and so on...?
[英]How to add a dictionary list to my code, so that it can run fine?
请朋友我需要你的帮助:
elif 'play music' in query:
songs_dir = 'C:/Users/SterlingTech/Music/SONGS'
music = os.listdir(songs_dir)
speak('What should I play?')
ans = TakeCommand().lower()
no = (ans.replace('number',''))
os.startfile(os.path.join(songs_dir,music[no]))
这是我得到的结果:
Traceback (most recent call last):
File "c:/Users/SterlingTech/Desktop/javis folder/javis 1.0.py", line 215, in <module>
os.startfile(os.path.join(songs_dir,music[no]))
TypeError: list indices must be integers or slices, not str
您可以尝试将no
转换为整数:
no = int(ans.replace('number',''))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.