Python Glossary Русский

all Python 3fnmatchfunction

fnmatch.fnmatchcase()

filename patterns

Like fnmatch(), but always case-sensitive and without path normalisation, so the result is the same on every OS.

Syntax

fnmatch.fnmatchcase(name, pat)

On Windows fnmatch() lower-cases both name and pattern and turns '/' into '\', while fnmatchcase() compares the strings as they are. When matching arbitrary strings rather than file names (tags, keys, test names), prefer fnmatchcase() so behaviour does not depend on the machine.

Examples

import fnmatch
print(fnmatch.fnmatchcase('A.PY', '*.py'))  # → False — на любой ОС
print(fnmatch.fnmatchcase('test_login', 'test_*'))  # → True
print(fnmatch.fnmatchcase('b', '[!a-c]'))  # → False — [!...] значит «кроме»

See also

Open in the full glossarydocs.python.orgReport an inaccuracy