[Tutor] list packing

Sean Perry shaleh at speakeasy.net
Mon Feb 27 08:34:06 CET 2006


John Fouhy wrote:
> On 27/02/06, kevin parks <kp8 at mac.com> wrote:
> 
>>snd = [f for f in os.listdir('/Users/kevin/snd/') if f.endswith('.aif')]
> 
> 
> If this is all you need, then you could do something like:
> 
> snd = ['/Users/kevin/snd/%s' % f for f in
> os.listdir('/Users/kevin/snd/') if f.endswith('.aif')]
> 
> Or, slightly more robustly (?),
> 
> snd = [os.path.join('/Users/kevin/snd', f) for f in
> os.listdir('/Users/kevin/snd/') if f.endswith('.aif')]
> 

os.path.join() is self-documenting. I find this to be a better reason to 
use it than anything else. But then my code only ever runs on Unix of 
some flavor.


More information about the Tutor mailing list