描述
方法fstat()返回有關與 fd 關聯的文件的信息。這是 fstat 方法返回的結構 -
st_dev− 包含文件的設備 ID
st_ino- 節點編號
st_mode− 保護
st_nlink- 硬鏈接的數量
st_uid− 所有者的用戶 ID
st_gid− 所有者的組 ID
st_rdev− 設備 ID(如果是特殊文件)
st_size- 總大小,以字節為單位
st_blksize− 文件係統 I/O 的塊大小
st_blocks- 分配的塊數
st_atime− 上次訪問時間
st_mtime− 上次修改時間
st_ctime− 上次狀態變化的時間
用法
以下是語法fstat()方法 -
os.fstat(fd)
參數
fd− 這是要為其返回係統信息的文件描述符。
返回值
此方法返回有關與 fd 關聯的文件的信息。
示例
下麵的例子展示了 fstat() 方法的用法。
#!/usr/bin/python3
import os, sys
# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Now get the touple
info = os.fstat(fd)
print ("File Info:", info)
# Now get uid of the file
print ("UID of the file:%d" % info.st_uid)
# Now get gid of the file
print ("GID of the file:%d" % info.st_gid)
# Close opened file
os.close( fd)
結果
當我們運行上述程序時,它會產生以下結果 -
File Info:os.stat_result(st_mode=33206, st_ino=2533274790483933, st_dev=1017554828, st_nlink=1, st_uid=0, st_gid=0, st_size=61, st_atime=1455562034, st_mtime=1455561637, st_ctime=1455561164) UID of the file:0 GID of the file:0
相關用法
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.fsync()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.fchmod()用法及代碼示例
- Python 3 os.fchown()用法及代碼示例
- Python 3 os.fpathconf()用法及代碼示例
- Python 3 os.fchdir()用法及代碼示例
- Python 3 os.ftruncate()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- 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.fstat() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。