stat() 方法执行给定路径上的统计系统调用。
语法
以下是 stat() 方法的语法:
os.stat(path)
参数
-
path -- 这是一个路径,其状态信息是必需的。
返回值
下面是 stat 结构的成员列表:
- st_mode: 保护位
- st_ino: inode编号
- st_dev: 设备
- st_nlink: 硬链接数
- st_uid: 所有者的用户ID
- st_gid: 所有者的组ID
- st_size: 文件的大小,以字节为单位
- st_atime: 最近访问时间
- st_mtime: 最新内容修改时间
- st_ctime: 最近元数据更改的时间
示例
下面的示例显示 stat() 方法的使用。
# !/usr/bin/python3 import os, sys # showing stat information of file "foo.txt" statinfo = os.stat('foo.txt') print (statinfo)
当我们运行上面的程序,它会产生以下结果:
os.stat_result(st_mode=33206, st_ino=281474976797706, st_dev=1017554828, st_nlink=1, st_uid=0, st_gid=0, st_size=13, st_atime=1455649253, st_mtime=1438077266, st_ctime=1455560006)
上一篇:
Python3文件方法
下一篇:
Python3 os文件目录的方法