Reputation: 3425
musicdb[56] is "C:\\Users\\Andrew\\song.mp3"
So I'm trying to pass a song onto mplayer, it works if I quote the song like like:
player = subprocess.Popen(["mplayer", "C:\\Users\\Andrew\\song.mp3"], creationflags = subprocess.CREATE_NEW_CONSOLE)
but
player = subprocess.Popen(["mplayer", musicdb[56]], creationflags = subprocess.CREATE_NEW_CONSOLE)
Doesn't work even though musicdb[56] is exactly the same string as used in the first example.
Can anyone explain why? I can't find anything on google.
Upvotes: 0
Views: 148
Reputation: 328810
To debug issues like this, I use this approach:
cmd = ["mplayer", musicdb[56]]
print repr(cmd)
subprocess.Popen(cmd, ...)
Using repr
, you can see all the odd stuff that might be hiding in an innocently looking string (like, for example, extra new line characters at the end).
Upvotes: 3