[Tutor] list packing
kevin parks
kp8 at mac.com
Mon Feb 27 09:27:02 CET 2006
John,
Thanks... i am liking this variation a tad more since it means i only
have to type the path in one place .... but it is akin to your second
one... i was (still am really) having a hard time understanding
how to apply path.join _and_ listdir .... sometimes list comprehensions
twist my brain but this one is worth studying ...
nice! two little lines that do a boatload of work! hee hee
----
pth = '/Users/kpp9c/snd/01'
samples = [os.path.join(pth, f) for f in os.listdir(pth) if f.endswith
('.aif')]
----
i could even add:
samples = [os.path.join(pth, f) for f in os.listdir(pth) if f.endswith
('.aif' & f.startswith('t')]
to make sublists in guess....
What i like about this is that i can chance my directory structure
(add/delete/rename/etc)
and shape it any way that i want and then Python reflects all my
restructuring... lovely...
Exactly the type of tedious thing i want Python to do for me *^-^*
cheers,
kevin
More information about the Tutor
mailing list