Aug-07-2019, 07:50 AM
Hello
I'm relatively new to Python. Whilst writing an mp3 player I encounter an error.
I have in a previous step created a simple textfile with paths to mp3 files. After reading the file I use a for loop
For testing purposes I also write variable line (full path to mp3 file) as well as variable path and filename after the split.
And change the working directory
If I instead directly write
Output of the prints are:
Path: C:\temp\ett\tva
Filename: 01-som_vatten.mp3
I cannot work out what is the difference between writing the mp3 filename directly and using a variable. Could it be the wrong variable typ?
Regards
Johan
I'm relatively new to Python. Whilst writing an mp3 player I encounter an error.
I have in a previous step created a simple textfile with paths to mp3 files. After reading the file I use a for loop
pygame.mixer.init() for i, line in enumerate(f): if i == 0: print(line) path, filename = os.path.split(line)So far nothing strange
For testing purposes I also write variable line (full path to mp3 file) as well as variable path and filename after the split.
And change the working directory
print('Path: ' + path) print('Filename: ' + filename) os.chdir(path)No to call the player (pygame) I use filename in the load() function and then play
pygame.mixer.music.load(filename) pygame.mixer.music.play()Getting the error pygame.error: "Couldn't open '01-som_vatten.mp3"
If I instead directly write
pygame.mixer.music.load('01-som_vatten.mp3')It works fine.
Output of the prints are:
Path: C:\temp\ett\tva
Filename: 01-som_vatten.mp3
I cannot work out what is the difference between writing the mp3 filename directly and using a variable. Could it be the wrong variable typ?
Regards
Johan