lib/os.py中没有找到os.stat函数,在python解释器环境中,显示os.stat为python内建函数
>>> os.stat
<built-in function stat>
os模块里没有stat的定义,stat是由平台依赖的 posix 、nt等内建模块提供的,看一下os模块的最开头部分。
r"""OS routines for Mac, NT, or Posix depending on what system we're on.
This exports:
- all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.
- os.path is one of the modules posixpath, or ntpath
- os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos'
- os.curdir is a string representing the current directory ('.' or ':')
- os.pardir is a string representing the parent directory ('..' or '::')
- os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
- os.extsep is the extension separator ('.' or '/')
- os.altsep is the alternate pathname separator (None or '/')
- os.pathsep is the component separator used in $PATH etc
- os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
- os.defpath is the default search path for executables
- os.devnull is the file path of the null device ('/dev/null', etc.)
Programs that import and use 'os' stand a better chance of being
portable between different platforms. Of course, they must then
only use functions that are defined by all platforms (e.g., unlink
and opendir), and leave all pathname manipulation to os.path
(e.g., split and join).
"""
def _get_exports_list(module):
try:
return list(module.__all__)
except AttributeError:
return [n for n in dir(module) if n[0] != '_']
if 'posix' in _names:
.......
import posix
__all__.extend(_get_exports_list(posix))
.......
elif 'nt' in _names:
.......
import nt
__all__.extend(_get_exports_list(nt))
.......
参考:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3762715&pid=22230940&page=1&extra=#pid22230940