== stat 模块 ==
[Example 1-50 #eg-1-50] 展示了 ``stat`` 模块的基本用法,
这个模块包含了一些 ``os.stat`` 函数中可用的常量和测试函数.
====Example 1-50. Using the stat Module====[eg-1-50]
```
File: stat-example-1.py
import stat
import os, time
st = os.stat("samples/sample.txt")
print "mode", "=>", oct(stat.S_IMODE(st[stat.ST_MODE]))
print "type", "=>",
if stat.S_ISDIR(st[stat.ST_MODE]):
print "DIRECTORY",
if stat.S_ISREG(st[stat.ST_MODE]):
print "REGULAR",
if stat.S_ISLNK(st[stat.ST_MODE]):
print "LINK",
print
print "size", "=>", st[stat.ST_SIZE]
print "last accessed", "=>", time.ctime(st[stat.ST_ATIME])
print "last modified", "=>", time.ctime(st[stat.ST_MTIME])
print "inode changed", "=>", time.ctime(st[stat.ST_CTIME])
*B*mode => 0664
type => REGULAR
size => 305
last accessed => Sun Oct 10 22:12:30 1999
last modified => Sun Oct 10 18:39:37 1999
inode changed => Sun Oct 10 15:26:38 1999*b*
```
python标准库介绍——3 stat 模块详解
最新推荐文章于 2025-03-02 13:00:00 发布
本文通过一个Python示例介绍了如何使用stat模块来获取文件的状态信息,包括文件类型、权限模式、大小及最后访问和修改时间等。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Python3.10
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
646

被折叠的 条评论
为什么被折叠?



