module-dircache.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.3 dircache -- Cached directory listings</title>
<META NAME="description" CONTENT="6.3 dircache -- Cached directory listings">
<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-stat.html" tppabs="http://www.python.org/doc/current/lib/module-stat.html">
<LINK REL="previous" href="module-os.path.html" tppabs="http://www.python.org/doc/current/lib/module-os.path.html">
<LINK REL="up" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">
<LINK REL="next" href="module-stat.html" tppabs="http://www.python.org/doc/current/lib/module-stat.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-os.path.html" tppabs="http://www.python.org/doc/current/lib/module-os.path.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-stat.html" tppabs="http://www.python.org/doc/current/lib/module-stat.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-os.path.html" tppabs="http://www.python.org/doc/current/lib/module-os.path.html">6.2 os.path </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-stat.html" tppabs="http://www.python.org/doc/current/lib/module-stat.html">6.4 stat </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION008300000000000000000">
6.3 <tt class="module">dircache</tt> --
Cached directory listings</A>
</H1>
<P>
<P>
The <tt class="module">dircache</tt> module defines a function for reading directory listing
using a cache, and cache invalidation using the <var>mtime</var> of the directory.
Additionally, it defines a function to annotate directories by appending
a slash.
<P>
The <tt class="module">dircache</tt> module defines the following functions:
<P>
<dl><dt><b><a name='l2h-1057'><tt class='function'>listdir</tt></a></b> (<var>path</var>)
<dd>
Return a directory listing of <var>path</var>, as gotten from
<tt class="function">os.listdir()</tt>. Note that unless <var>path</var> changes, further call
to <tt class="function">listdir()</tt> will not re-read the directory structure.
<P>
Note that the list returned should be regarded as read-only. (Perhaps
a future version should change it to return a tuple?)
</dl>
<P>
<dl><dt><b><a name='l2h-1058'><tt class='function'>opendir</tt></a></b> (<var>path</var>)
<dd>
Same as <tt class="function">listdir()</tt>. Defined for backwards compatibility.
</dl>
<P>
<dl><dt><b><a name='l2h-1059'><tt class='function'>annotate</tt></a></b> (<var>head, list</var>)
<dd>
Assume <var>list</var> is a list of paths relative to <var>head</var>, and append,
in place, a "<tt class="character">/</tt>" to each path which points to a directory.
</dl>
<P>
<dl><dd><pre class="verbatim">
>>> import dircache
>>> a=dircache.listdir('/')
>>> a=a[:] # Copy the return value so we can change 'a'
>>> a
['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+
found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']
>>> dircache.annotate('/', a)
>>> a
['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm
linuz']
</pre></dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-os.path.html" tppabs="http://www.python.org/doc/current/lib/module-os.path.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-stat.html" tppabs="http://www.python.org/doc/current/lib/module-stat.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-os.path.html" tppabs="http://www.python.org/doc/current/lib/module-os.path.html">6.2 os.path </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-stat.html" tppabs="http://www.python.org/doc/current/lib/module-stat.html">6.4 stat </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 + -