summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-13 07:51:04 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-13 07:51:04 (GMT)
commit0a24d105244c39aeaa67db51d0b38e48402d252d (patch)
tree059d379de78f285a83796668cb4fd63a0988e001 /Doc
parente19d7a3c0ac25680d2f72669f1441dadbb2f9a41 (diff)
downloadcpython-0a24d105244c39aeaa67db51d0b38e48402d252d.zip
cpython-0a24d105244c39aeaa67db51d0b38e48402d252d.tar.gz
cpython-0a24d105244c39aeaa67db51d0b38e48402d252d.tar.bz2
Patch #1679379: add documentation for fnmatch.translate().
(backport from rev. 54323)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libfnmatch.tex31
1 files changed, 31 insertions, 0 deletions
diff --git a/Doc/lib/libfnmatch.tex b/Doc/lib/libfnmatch.tex
index fc4b97a..1ac46bd 100644
--- a/Doc/lib/libfnmatch.tex
+++ b/Doc/lib/libfnmatch.tex
@@ -36,6 +36,19 @@ 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}
@@ -50,6 +63,24 @@ 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}