描述
方法stat()在給定的路徑上執行 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)
相關用法
- Python 3 os.statvfs()用法及代碼示例
- Python 3 os.stat_float_times()用法及代碼示例
- Python 3 os.symlink()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
- Python 3 os.mknod()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.stat() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。