More Efficient fnmatch.fnmatch for multiple patterns?

Gabriel Genellina gagsl-py at
Mon Jan 8 19:48:26 CET 2007

At Monday 8/1/2007 15:10, abcd wrote:

>I am using fnmatch.fnmatch to find some files.  The only problem I have
>is that it only takes one 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
> there a built-in function that will match using multiple patterns?

matched = any(fnmatch(filename, p) for p in patterns)

Gabriel Genellina
Softlab SRL 


Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 

More information about the Python-list mailing list