Hi Terry, > > But that's not "using your existing... functional-programming > > thingy" mentioned above. > > > > mp3_files = sorted(os.path.join(mp3_subdir, x) for x in > > filter(lambda f: f.lower().endswith(".mp3"), os.listdir(mp3_subdir))) > > No it's not, but that bit of code produces a list of files, including > paths, separated by commas (all the os methods that I tried (such as > os.list dir do).
No, it produces a `list', a Python type that's an array-like data structure that can change length. You've been writing lists literally with brackets in your code, e.g. Popen() is being passed one parameter here: subprocess.Popen(['mpg321', '-q', '-m', '-a', 'hw:0,0', 'foo.mp3']) Python prints lists with commas between items, but a list isn't a string and the commas are just formatting. You need to join your mp3_files list onto the end of your hard-coded ['mpg321'...] one so Popen() sees just one long list. https://docs.python.org/2/tutorial/introduction.html#lists > I suspected as much. Presumably in the shell the * is expanded before > it is given to mpg321 (without commas) so it works. Yes, unlike DOS, glob expansion is normally done by the shell and programs just see literal file names to process. This aids consistency as each program doesn't develop their own dialect, and allows centralised improvements, e.g. bash's `**' globstar. Historically, it was a separate program to the shell due to memory constraints, called glob(1), but these days shells have it built in, and larger languages provide similar logic in libraries, e.g. glob.glob(). Cheers, Ralph. -- Next meeting: Bournemouth, Tuesday, 2017-03-07 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR