Filesystem and I/O Modules

fnmatch

Matches filenames against shell-style patterns such as *, ? and character ranges. Unlike regular expressions, these patterns describe whole strings. fnmatch() applies host case normalization; fnmatchcase() preserves case distinctions. Path separators have no special meaning to these matching functions.

Formal Syntax & Structure

python syntaxpython
import fnmatch

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from fnmatch import filternames = ["notes.txt", "report.csv", "todo.txt"]print(filter(names, "*.txt"))
Python Reference