描述
方法lstat()非常類似於 fstat() 並返回一個stat_result 包含有關文件信息的對象,但不遵循符號鏈接。這是不支持符號鏈接的平台(如 Windows)上 fstat() 的別名。
這是 lstat 方法返回的結構 -
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− 上次狀態變化的時間
用法
以下是語法lstat()方法 -
os.lstat(path)
參數
path- 這是將返回信息的文件。
返回值
此方法返回有關文件的信息。
示例
下麵的例子展示了 lstat() 方法的用法。
#!/usr/bin/python3
import os, sys
# Open a file
path = "d:\\python3\\foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close opened file
os.close( fd )
# Now get the touple
info = os.lstat(path)
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)
結果
當我們運行上述程序時,它會產生以下結果 -
File Info:os.stat_result(st_mode=33206, st_ino=281474976797706, st_dev=1017554828, st_nlink=2, st_uid=0, st_gid=0, st_size=13, st_atime=1455597777, st_mtime=1438077266, st_ctime=1455560006) UID of the file:0 GID of the file:0
相關用法
- Python 3 os.lseek()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
- Python 3 os.lchmod()用法及代碼示例
- Python 3 os.lchflags()用法及代碼示例
- Python 3 os.link()用法及代碼示例
- Python 3 os.listdir()用法及代碼示例
- 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.lstat() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。