O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

fnmatch

The fnmatch module provides support for matching filenames using UNIX shell-style wildcard characters:

Character(s)Description
*Matches everything
?Matches any single character
[seq]Matches any character in seq
[!seq]Matches any character not in seq

The following functions can be used to test for a wildcard match:


fnmatch(filename, pattern)

Returns True or False depending on whether filename matches pattern. Case sensitivity depends on the operating system (and may be non–case sensitive on certain platforms such as Windows).


fnmatchcase(filename, pattern)

Performs a case-sensitive comparison of filename against pattern.

Example


fnmatch('foo.gif', '*.gif')              # Returns True
fnmatch('part37.html', 'part3[0-5].html')# Returns False

See Also ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required