[Python-checkins] r54323 - in python/trunk: Doc/lib/libfnmatch.tex Misc/NEWS

georg.brandl python-checkins at python.org
Tue Mar 13 08:50:59 CET 2007


Author: georg.brandl
Date: Tue Mar 13 08:50:57 2007
New Revision: 54323

Modified:
   python/trunk/Doc/lib/libfnmatch.tex
   python/trunk/Misc/NEWS
Log:
Patch #1679379: add documentation for fnmatch.translate().


Modified: python/trunk/Doc/lib/libfnmatch.tex
==============================================================================
--- python/trunk/Doc/lib/libfnmatch.tex	(original)
+++ python/trunk/Doc/lib/libfnmatch.tex	Tue Mar 13 08:50:57 2007
@@ -36,6 +36,19 @@
 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 @@
 \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}

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Mar 13 08:50:57 2007
@@ -594,6 +594,8 @@
 Documentation
 -------------
 
+- Patch #1679379: add documentation for fnmatch.translate().
+
 - Bug #1629566: clarify the docs on the return values of parsedate()
   and parsedate_tz() in email.utils and rfc822.
 


More information about the Python-checkins mailing list