📄 module-fnmatch.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.20 fnmatch -- Unix filename pattern matching</title>
<META NAME="description" CONTENT="6.20 fnmatch -- Unix filename pattern matching">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-shutil.html" tppabs="http://www.python.org/doc/current/lib/module-shutil.html">
<LINK REL="previous" href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html">
<LINK REL="up" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">
<LINK REL="next" href="module-shutil.html" tppabs="http://www.python.org/doc/current/lib/module-shutil.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-shutil.html" tppabs="http://www.python.org/doc/current/lib/module-shutil.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html">6.19 glob </A>
<b class="navlabel">Up:</b> <a class="sectref" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">6. Generic Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-shutil.html" tppabs="http://www.python.org/doc/current/lib/module-shutil.html">6.21 shutil </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0082000000000000000000">
6.20 <tt class="module">fnmatch</tt> --
Unix filename pattern matching</A>
</H1>
<P>
<P>
<P>
This module provides support for Unix shell-style wildcards, which
are <i>not</i> the same as regular expressions (which are documented
in the <tt class='module'><a href="module-re.html" tppabs="http://www.python.org/doc/current/lib/module-re.html">re</a></tt> module). The special
characters used in shell-style wildcards are:
<P>
<table border align="center" style="border-collapse: collapse">
<thead>
<tr class="tableheader">
<th align="center"><b>Pattern</b> </th>
<th align="left"><b>Meaning</b> </th>
</thead>
<tbody valign='baseline'>
<tr><td align="center" valign="baseline"><code>*</code></td>
<td align="left">matches everything</td>
<tr><td align="center" valign="baseline"><code>?</code></td>
<td align="left">matches any single character</td>
<tr><td align="center" valign="baseline"><code>[<var>seq</var>]</code></td>
<td align="left">matches any character in <var>seq</var></td>
<tr><td align="center" valign="baseline"><code>[!<var>seq</var>]</code></td>
<td align="left">matches any character not in <var>seq</var></td></tbody>
</table>
<P>
Note that the filename separator (<code>'/'</code> on Unix) is <i>not</i>
special to this module. See module
<tt class='module'><a href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html">glob</a></tt> for pathname expansion
(<tt class='module'><a href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html">glob</a></tt> uses <tt class="function">fnmatch()</tt> to match pathname
segments). Similarly, filenames starting with a period are
not special for this module, and are matched by the <code>*</code> and
<code>?</code> patterns.
<P>
<dl><dt><b><a name='l2h-1475'><tt class='function'>fnmatch</tt></a></b> (<var>filename, pattern</var>)
<dd>
Test whether the <var>filename</var> string matches the <var>pattern</var>
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 <tt class="function">fnmatchcase()</tt>
instead.
</dl>
<P>
<dl><dt><b><a name='l2h-1476'><tt class='function'>fnmatchcase</tt></a></b> (<var>filename, pattern</var>)
<dd>
Test whether <var>filename</var> matches <var>pattern</var>, returning true or
false; the comparison is case-sensitive.
</dl>
<P>
<div class='seealso'>
<p class='heading'><b>See Also:</b></p>
<dl compact class="seemodule">
<dt>Module <b><tt class='module'><a href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html">glob</a></tt>:</b>
<dd>Unix shell-style path expansion.
</dl>
</div>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-shutil.html" tppabs="http://www.python.org/doc/current/lib/module-shutil.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-glob.html" tppabs="http://www.python.org/doc/current/lib/module-glob.html">6.19 glob </A>
<b class="navlabel">Up:</b> <a class="sectref" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">6. Generic Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-shutil.html" tppabs="http://www.python.org/doc/current/lib/module-shutil.html">6.21 shutil </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -