[Tutor] Better way - fnmatch with list ? CORRECTION

Mark Tolonen metolone+gmane at gmail.com
Sat Jan 3 22:35:51 CET 2009

"Damon Timm" <damontimm at gmail.com> wrote in message 
news:262679b50901031327n23b2f754l62fe0cf98751c1e5 at mail.gmail.com...
> On Fri, Jan 2, 2009 at 7:16 PM, Jervis Whitley <jervisau at gmail.com> wrote:
>> for fn in files:
>>   base, ext = os.path.splitext(fn)
>>   if ext.lower() in ['.flac', '.mp3', '.mp4']:
>> takes into account systems with case sensitive filenames.
> Thanks!  Will throw that in there.  I'm getting it ... bit by little bit.

fnmatch already takes into account systems with case-sensitive filenames:

>>> help(fnmatch.fnmatch)
Help on function fnmatch in module fnmatch:

fnmatch(name, pat)
    Test whether FILENAME matches PATTERN.

    Patterns are Unix shell style:

    *       matches everything
    ?       matches any single character
    [seq]   matches any character in seq
    [!seq]  matches any char not in seq

    An initial period in FILENAME is not special.
    Both FILENAME and PATTERN are first case-normalized
    if the operating system requires it.
    If you don't want this, use fnmatchcase(FILENAME, PATTERN).


More information about the Tutor mailing list