More Efficient fnmatch.fnmatch for multiple patterns?

Brian Beck exogen at gmail.com
Mon Jan 8 13:35:28 EST 2007


abcd wrote:
> I am using fnmatch.fnmatch to find some files.  The only problem I have
> is that it only takes one pattern...so if I want to search using
> multiple patterns I have to do something like....
> 
> patterns = ['abc*.txt', 'foo*']
> 
> for p in patterns:
>     if fnmatch.fnmatch(some_file_name, p):
>         return True

I don't see anything in the fnmatch and glob modules... but I didn't look
very hard because what the heck is wrong with the four line solution you
have? Looks fine to me.

-- 
Brian Beck
Adventurer of the First Order




More information about the Python-list mailing list