您的位置:首页 > 编程语言 > Python开发

os.stat怎么成了python的内建函数呢?

2012-08-02 22:10 369 查看
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

http://topic.csdn.net/u/20120801/22/19a5750a-37e2-4440-910b-05c88183be31.html?seed=304111345&r=79293043#r_79293043
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: