Python的lseek()
方法與fstat()
非常相似,並返回一個包含有關檔資訊的stat_result
對象,但不要跟隨符號鏈接。這是在不支持符號鏈接的平臺上的fstat()
的別名,例如:Windows。
這是lstat
方法返回的結構 -
st_dev
- 包含檔的設備的IDst_ino
- inode編號st_mode
- 保護st_nlink
- 硬鏈接數st_uid
- 所有者的用戶IDst_gid
- 所有者的組IDst_rdev
- 設備ID(如果是特殊檔)st_size
- 總大小(以位元組為單位)st_blksize
- 檔系統I/O的塊大小st_blocks
- 分配的塊數st_atime
- 上次訪問的時間st_mtime
- 上次修改的時間st_ctime
- 上次狀態更改的時間
語法
以下是lstat()
方法的語法 -
os.lstat(path)
參數
- path - 這是檔描述符,需要處理。
定義的pos
常數 -
os.SEEK_SET = 0
os.SEEK_CUR = 1
os.SEEK_END = 2
返回值
- 這是要返回資訊的檔。
示例
以下示例顯示了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 os模組方法
下一篇:
Python異常處理