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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值