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檔目錄的方法