Python os.fstat() 方法
python os.fstat() 方法
os.fstat() 方法用于返回文件描述符fd的狀態(tài),類似 stat()。
unix,windows上可用。
fstat 方法返回的結(jié)構(gòu):
- st_dev: 設(shè)備信息
- st_ino: 文件的i-node值
- st_mode: 文件信息的掩碼,包含了文件的權(quán)限信息,文件的類型信息(是普通文件還是管道文件,或者是其他的文件類型)
- st_nlink: 硬連接數(shù)
- st_uid: 用戶id
- st_gid: 用戶組 id
- st_rdev: 設(shè)備 id (如果指定文件)
- st_size: 文件大小,以byte為單位
- st_blksize: 系統(tǒng) i/o 塊大小
- st_blocks: 文件的是由多少個(gè) 512 byte 的塊構(gòu)成的
- st_atime: 文件最近的訪問時(shí)間
- st_mtime: 文件最近的修改時(shí)間
- st_ctime: 文件狀態(tài)信息的修改時(shí)間(不是文件內(nèi)容的修改時(shí)間)
語法
fstat()方法語法格式如下:
os.fstat(fd)
參數(shù)
- fd -- 文件的描述符。
返回值
返回文件描述符fd的狀態(tài)。
實(shí)例
以下實(shí)例演示了 fstat() 方法的使用:
#!/usr/bin/python # -*- coding: utf-8 -*- import os, sys # 打開文件 fd = os.open( "foo.txt", os.o_rdwr|os.o_creat ) # 獲取元組 info = os.fstat(fd) print "文件信息 :", info # 獲取文件 uid print "文件 uid :%d" % info.st_uid # 獲取文件 gid print "文件 gid :%d" % info.st_gid # 關(guān)閉文件 os.close( fd)
執(zhí)行以上程序輸出結(jié)果為:
文件信息 : (33261, 3753776l, 103l, 1, 0, 0, 102l, 1238783197, 1238786767, 1238786767) 文件 uid :0 文件 gid :0
相關(guān)文章
- Python 環(huán)境搭建
- Python 循環(huán)語句
- Python pass 語句
- Python 日期和時(shí)間
- Python 模塊
- Python 異常處理
- Python 正則表達(dá)式
- Python 操作 MySQL 數(shù)據(jù)庫
- Python 多線程
- Python 列表
- Python 棧
- Python 哈希表
- Python 堆
- Python 排序算法
- Python3 教程
- Python3 字符串(String)
- Python3 for while 循環(huán)語句
- Python3 錯(cuò)誤和異常
- Python3 多線程
- Python3 XML 解析