[Tutor] Better way - fnmatch with list ?
Damon Timm
damontimm at gmail.com
Sat Jan 3 01:06:06 CET 2009
On Fri, Jan 2, 2009 at 6:44 PM, bob gailer <bgailer at gmail.com> wrote:
> Since file is a built-in function it is a good idea to not use it as a
> variable name.
Oooh! I did not know that ... thanks ... went through and changed them all.
> for fn in files:
> base, ext = os.path.splitext(fn)
> if ext in ['*.flac','*.mp3','*.m4a']:
> #do some stuff if the someFile matches one of the items in the list
I caught the * bit - I must be learning!
One thought though ... because fnmatch ignores case I could get away
with: .FLAC, .flac, .FLac, or any other such foolishness for file
extensions ...
Using the above approach, however, matches by case ... so, I think, to
be safe, I would have to list each iteration of the case in the list
... is there a way to account for that ?
Thanks again -
Damon
More information about the Tutor
mailing list