summaryrefslogtreecommitdiff
path: root/sys/src/cmd/python/Doc/lib/libfnmatch.tex
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
committercinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
commit458120dd40db6b4df55a4e96b650e16798ef06a0 (patch)
tree8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Doc/lib/libfnmatch.tex
parent3a742c699f6806c1145aea5149bf15de15a0afd7 (diff)
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Doc/lib/libfnmatch.tex')
-rw-r--r--sys/src/cmd/python/Doc/lib/libfnmatch.tex86
1 files changed, 86 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Doc/lib/libfnmatch.tex b/sys/src/cmd/python/Doc/lib/libfnmatch.tex
new file mode 100644
index 000000000..1ac46bdd4
--- /dev/null
+++ b/sys/src/cmd/python/Doc/lib/libfnmatch.tex
@@ -0,0 +1,86 @@
+\section{\module{fnmatch} ---
+ \UNIX{} filename pattern matching}
+
+\declaremodule{standard}{fnmatch}
+\modulesynopsis{\UNIX\ shell style filename pattern matching.}
+
+
+\index{filenames!wildcard expansion}
+
+This module provides support for \UNIX{} shell-style wildcards, which
+are \emph{not} the same as regular expressions (which are documented
+in the \refmodule{re}\refstmodindex{re} module). The special
+characters used in shell-style wildcards are:
+
+\begin{tableii}{c|l}{code}{Pattern}{Meaning}
+ \lineii{*}{matches everything}
+ \lineii{?}{matches any single character}
+ \lineii{[\var{seq}]}{matches any character in \var{seq}}
+ \lineii{[!\var{seq}]}{matches any character not in \var{seq}}
+\end{tableii}
+
+Note that the filename separator (\code{'/'} on \UNIX) is \emph{not}
+special to this module. See module
+\refmodule{glob}\refstmodindex{glob} for pathname expansion
+(\refmodule{glob} uses \function{fnmatch()} to match pathname
+segments). Similarly, filenames starting with a period are
+not special for this module, and are matched by the \code{*} and
+\code{?} patterns.
+
+
+\begin{funcdesc}{fnmatch}{filename, pattern}
+Test whether the \var{filename} string matches the \var{pattern}
+string, returning true or false. If the operating system is
+case-insensitive, then both parameters will be normalized to all
+lower- or upper-case before the comparison is performed. If you
+require a case-sensitive comparison regardless of whether that's
+standard for your operating system, use \function{fnmatchcase()}
+instead.
+
+This example will print all file names in the current directory with the
+extension \code{.txt}:
+
+\begin{verbatim}
+import fnmatch
+import os
+
+for file in os.listdir('.'):
+ if fnmatch.fnmatch(file, '*.txt'):
+ print file
+\end{verbatim}
+
+\end{funcdesc}
+
+\begin{funcdesc}{fnmatchcase}{filename, pattern}
+Test whether \var{filename} matches \var{pattern}, returning true or
+false; the comparison is case-sensitive.
+\end{funcdesc}
+
+\begin{funcdesc}{filter}{names, pattern}
+Return the subset of the list of \var{names} that match \var{pattern}.
+It is the same as \code{[n for n in names if fnmatch(n, pattern)]}, but
+implemented more efficiently.
+\versionadded{2.2}
+\end{funcdesc}
+
+\begin{funcdesc}{translate}{pattern}
+Return the shell-style \var{pattern} converted to a regular
+expression.
+
+Example:
+
+\begin{verbatim}
+>>> import fnmatch, re
+>>>
+>>> regex = fnmatch.translate('*.txt')
+>>> regex
+'.*\\.txt$'
+>>> reobj = re.compile(regex)
+>>> print reobj.match('foobar.txt')
+<_sre.SRE_Match object at 0x...>
+\end{verbatim}
+\end{funcdesc}
+
+\begin{seealso}
+ \seemodule{glob}{\UNIX{} shell-style path expansion.}
+\end{seealso}