Raw Strings (I Think)
fredrik at pythonware.com
Wed Jul 23 22:43:31 CEST 2008
>> No, it doesn't. Instead of guessing what the cause might be, please show
>> us your code and show us the error message you're getting, so that we can
>> determine what the cause really is.
> Ok, sorry. Heres my code:
> import glob
> import random
> import os
> songs = glob.glob('C:\###\###\###\*.mp3')
> pick = random.choice(songs)
> And yes, I know there are better ways of randomly selecting
> a .mp3 file to play but I don't care.
my guess is that the real problem is that you get back filenames with
spaces in them, which gets treated as multiple arguments by os.system.
using os.startfile will fix this:
>>> import glob, os, random
>>> file = random.choice(glob.glob("\\music\\*.mp3"))
'\\music\\Madrugada - Grit - 05 - Seven Seconds.mp3'
>>> print file
\music\Madrugada - Grit - 05 - Seven Seconds.mp3
'\music\Madrugada' is not recognized as an internal or external command,
operable program or batch file.
... music starts playing ...
More information about the Python-list