source: vendor/python/2.5/Doc/lib/libfnmatch.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.0 KB
Line 
1\section{\module{fnmatch} ---
2 \UNIX{} filename pattern matching}
3
4\declaremodule{standard}{fnmatch}
5\modulesynopsis{\UNIX\ shell style filename pattern matching.}
6
7
8\index{filenames!wildcard expansion}
9
10This module provides support for \UNIX{} shell-style wildcards, which
11are \emph{not} the same as regular expressions (which are documented
12in the \refmodule{re}\refstmodindex{re} module). The special
13characters used in shell-style wildcards are:
14
15\begin{tableii}{c|l}{code}{Pattern}{Meaning}
16 \lineii{*}{matches everything}
17 \lineii{?}{matches any single character}
18 \lineii{[\var{seq}]}{matches any character in \var{seq}}
19 \lineii{[!\var{seq}]}{matches any character not in \var{seq}}
20\end{tableii}
21
22Note that the filename separator (\code{'/'} on \UNIX) is \emph{not}
23special to this module. See module
24\refmodule{glob}\refstmodindex{glob} for pathname expansion
25(\refmodule{glob} uses \function{fnmatch()} to match pathname
26segments). Similarly, filenames starting with a period are
27not special for this module, and are matched by the \code{*} and
28\code{?} patterns.
29
30
31\begin{funcdesc}{fnmatch}{filename, pattern}
32Test whether the \var{filename} string matches the \var{pattern}
33string, returning true or false. If the operating system is
34case-insensitive, then both parameters will be normalized to all
35lower- or upper-case before the comparison is performed. If you
36require a case-sensitive comparison regardless of whether that's
37standard for your operating system, use \function{fnmatchcase()}
38instead.
39\end{funcdesc}
40
41\begin{funcdesc}{fnmatchcase}{filename, pattern}
42Test whether \var{filename} matches \var{pattern}, returning true or
43false; the comparison is case-sensitive.
44\end{funcdesc}
45
46\begin{funcdesc}{filter}{names, pattern}
47Return the subset of the list of \var{names} that match \var{pattern}.
48It is the same as \code{[n for n in names if fnmatch(n, pattern)]}, but
49implemented more efficiently.
50\versionadded{2.2}
51\end{funcdesc}
52
53\begin{seealso}
54 \seemodule{glob}{\UNIX{} shell-style path expansion.}
55\end{seealso}
Note: See TracBrowser for help on using the repository browser.