Python fnmatch Module
Example
Filter names using shell-style wildcards:
import fnmatch
names = ["Emil.txt", "Tobias.py", "Linus.txt"]
print(sorted(fnmatch.filter(names, "*.txt")))
Try it Yourself »
Definition and Usage
The fnmatch module matches filenames using Unix shell-style wildcards.
Use it to filter directory listings or any list of strings using patterns like *.py, data-??.csv, etc.
Members
Member | Description |
---|---|
filter() | Return the subset of names that match a pattern. |
fnmatch() | Test whether a filename matches a pattern. |
fnmatchcase() | Like fnmatch but case-sensitive on all platforms. |