Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 os.fstat() Method

Python3 os.fstat() Method

Python3 OS File/Directory Methods Python3 OS File/Directory Methods


Overview

The os.fstat() method returns the status of the file descriptor fd, similar to stat().

Available on Unix and Windows.

The structure returned by the fstat method:

Syntax

The **fstat()** method syntax is as follows:


os.fstat(fd)

Parameters

Return Value

Returns the status of the file descriptor fd.

Example

The following example demonstrates the use of the fstat() method:


#!/usr/bin/python3

import os, sys

# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Get tuple
info = os.fstat(fd)

print ("文件信息 :", info)

# Get file uid
print ("文件 UID :%d" % info.st_uid)

# Get file gid
print ("文件 GID  :%d" % info.st_gid)

# Close file
os.close( fd)

The output of the above program is:


文件信息 : (33261, 3753776L, 103L, 1, 0, 0, 
            102L, 1238783197, 1238786767, 1238786767)
文件 UID :0
文件 GID :0

Python3 OS File/Directory Methods Python3 OS File/Directory Methods