⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-stat.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.4 stat -- Interpreting stat() results</title>
<META NAME="description" CONTENT="6.4 stat -- Interpreting stat() results">
<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-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.html">
<LINK REL="previous" href="module-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.html">
<LINK REL="up" href="allos.html" tppabs="http://www.python.org/doc/current/lib/allos.html">
<LINK REL="next" href="module-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.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-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.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-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.html">6.3 dircache  </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-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.html">6.5 statcache  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION008400000000000000000">
6.4 <tt class="module">stat</tt> --
         Interpreting <tt class="function">stat()</tt> results</A>
</H1>

<P>


<P>
The <tt class="module">stat</tt> module defines constants and functions for
interpreting the results of <tt class="function">os.stat()</tt>,
<tt class="function">os.fstat()</tt> and <tt class="function">os.lstat()</tt> (if they exist).  For
complete details about the <tt class="cfunction">stat()</tt>, <tt class="cfunction">fstat()</tt> and
<tt class="cfunction">lstat()</tt> calls, consult the documentation for your system.

<P>
The <tt class="module">stat</tt> module defines the following functions to test for
specific file types:

<P>
<dl><dt><b><a name='l2h-1061'><tt class='function'>S_ISDIR</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a directory.
</dl>

<P>
<dl><dt><b><a name='l2h-1062'><tt class='function'>S_ISCHR</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a character special device file.
</dl>

<P>
<dl><dt><b><a name='l2h-1063'><tt class='function'>S_ISBLK</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a block special device file.
</dl>

<P>
<dl><dt><b><a name='l2h-1064'><tt class='function'>S_ISREG</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a regular file.
</dl>

<P>
<dl><dt><b><a name='l2h-1065'><tt class='function'>S_ISFIFO</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a FIFO (named pipe).
</dl>

<P>
<dl><dt><b><a name='l2h-1066'><tt class='function'>S_ISLNK</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a symbolic link.
</dl>

<P>
<dl><dt><b><a name='l2h-1067'><tt class='function'>S_ISSOCK</tt></a></b> (<var>mode</var>)
<dd>
Return non-zero if the mode is from a socket.
</dl>

<P>
Two additional functions are defined for more general manipulation of
the file's mode:

<P>
<dl><dt><b><a name='l2h-1068'><tt class='function'>S_IMODE</tt></a></b> (<var>mode</var>)
<dd>
Return the portion of the file's mode that can be set by
<tt class="function">os.chmod()</tt>--that is, the file's permission bits, plus the
sticky bit, set-group-id, and set-user-id bits (on systems that support
them).
</dl>

<P>
<dl><dt><b><a name='l2h-1069'><tt class='function'>S_IFMT</tt></a></b> (<var>mode</var>)
<dd>
Return the portion of the file's mode that describes the file type (used
by the <tt class="function">S_IS*()</tt> functions above).
</dl>

<P>
Normally, you would use the <tt class="function">os.path.is*()</tt> functions for
testing the type of a file; the functions here are useful when you are
doing multiple tests of the same file and wish to avoid the overhead of
the <tt class="cfunction">stat()</tt> system call for each test.  These are also
useful when checking for information about a file that isn't handled
by <tt class='module'><a href="module-os.path.html" tppabs="http://www.python.org/doc/current/lib/module-os.path.html">os.path</a></tt>, like the tests for block and character
devices.

<P>
All the variables below are simply symbolic indexes into the 10-tuple
returned by <tt class="function">os.stat()</tt>, <tt class="function">os.fstat()</tt> or
<tt class="function">os.lstat()</tt>.

<P>
<dl><dt><b><a name='l2h-1070'><tt>ST_MODE</tt></a></b>
<dd>
Inode protection mode.
</dl>

<P>
<dl><dt><b><a name='l2h-1071'><tt>ST_INO</tt></a></b>
<dd>
Inode number.
</dl>

<P>
<dl><dt><b><a name='l2h-1072'><tt>ST_DEV</tt></a></b>
<dd>
Device inode resides on.
</dl>

<P>
<dl><dt><b><a name='l2h-1073'><tt>ST_NLINK</tt></a></b>
<dd>
Number of links to the inode.
</dl>

<P>
<dl><dt><b><a name='l2h-1074'><tt>ST_UID</tt></a></b>
<dd>
User id of the owner.
</dl>

<P>
<dl><dt><b><a name='l2h-1075'><tt>ST_GID</tt></a></b>
<dd>
Group id of the owner.
</dl>

<P>
<dl><dt><b><a name='l2h-1076'><tt>ST_SIZE</tt></a></b>
<dd>
File size in bytes.
</dl>

<P>
<dl><dt><b><a name='l2h-1077'><tt>ST_ATIME</tt></a></b>
<dd>
Time of last access.
</dl>

<P>
<dl><dt><b><a name='l2h-1078'><tt>ST_MTIME</tt></a></b>
<dd>
Time of last modification.
</dl>

<P>
<dl><dt><b><a name='l2h-1079'><tt>ST_CTIME</tt></a></b>
<dd>
Time of last status change (see manual pages for details).
</dl>

<P>
Example:

<P>
<dl><dd><pre class="verbatim">
import os, sys
from stat import *

def walktree(dir, callback):
    '''recursively descend the directory rooted at dir,
       calling the callback function for each regular file'''

    for f in os.listdir(dir):
        pathname = '%s/%s' % (dir, f)
        mode = os.stat(pathname)[ST_MODE]
        if S_ISDIR(mode):
            # It's a directory, recurse into it
            walktree(pathname, callback)
        elif S_ISREG(mode):
            # It's a file, call the callback function
            callback(pathname)
        else:
            # Unknown file type, print a message
            print 'Skipping %s' % pathname

def visitfile(file):
    print 'visiting', file

if __name__ == '__main__':
    walktree(sys.argv[1], visitfile)
</pre></dl>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.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-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.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-dircache.html" tppabs="http://www.python.org/doc/current/lib/module-dircache.html">6.3 dircache  </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-statcache.html" tppabs="http://www.python.org/doc/current/lib/module-statcache.html">6.5 statcache  </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 + -