-1

When using module pyglet, giving the name of mp3 explicitly like sound="10.mp3", it works. When using module playsound and giving filenames as variable, playsound(str(play_num) + '.mp3'), it does work.

playsound(str(play_num)+'.mp3')

But when applying variable name of file to pyglet just like below, sound = "str(play_num)+'.mp3'", it does not work.

sound = "str(play_num)+'.mp3'"

it shows FileNotFoundError. How can I solve this problem??? In addition how to get the files from other directory and some other folder? When getting a sound file in other directory/folder using variable ?

player = pyglet.media.Player()
sound = "str(play_num)+'.mp3'"
src = pyglet.media.load(sound)
player.queue(src)
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • why `sound` is inside quotations?! – Hossein Heydari Jan 20 '21 at 10:11
  • because when using explicit file name, there are quotations like sound = ".\\S-WORD-E-SE-B-V-2\\10.mp3" it did work. – Jongkeun Choi Jan 20 '21 at 10:34
  • 1
    `sound = str(play_num)+'.mp3'` –  Jan 20 '21 at 11:40
  • Yes, but this case is when the sound files are in the current working directory. if when the sound files are in the other folder, how can i write on one sentence ? I solved this with two split sentences like [os.chdir("location of sound files")/ playsound(str(play_num)+'.mp3'] . It does work, But is it possible to combine these two in one sentence? – Jongkeun Choi Jan 22 '21 at 11:09
  • You have too many quotes... You have `"str(play_num)+'.mp3'"` when it should just be `str(play_num)+'.mp3'` – Tomerikoo Oct 04 '21 at 06:43

1 Answers1

0

Use F-String:

sound = f"{play_num}.mp3"
Hossein Heydari
  • 1,439
  • 9
  • 28