YouTip LogoYouTip

Os Fstat

# Python2.x Python os.fstat() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The os.fstat() method is used to return the status of the file descriptor fd, similar to stat(). Available on Unix and Windows. The structure returned by the fstat method: * **st_dev:** Device information * **st_ino:** The i-node value of the file * **st_mode:** Mask for file information, containing file permission information and file type information (whether it's a regular file, a pipe, or another file type) * **st_nlink:** Number of hard links * **st_uid:** User ID * **st_gid:** Group ID * **st_rdev:** Device ID (if the specified file is a device file) * **st_size:** File size in bytes * **st_blksize:** System I/O block size * **st_blocks:** Number of 512-byte blocks the file consists of * **st_atime:** Time of most recent access to the file * **st_mtime:** Time of most recent modification of the file * **st_ctime:** Time of most recent status change of the file (not the time of modification of the file content) ### Syntax The syntax for the **fstat()** method is as follows: os.fstat(fd) ### Parameters * **fd** -- The file descriptor. ### Return Value Returns the status of the file descriptor fd. ### Example The following example demonstrates the use of the fstat() method: #!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Get the tuple info = os.fstat(fd)print "File info :", info # Get file uidprint "File UID :%d" % info.st_uid # Get file gidprint "File GID :%d" % info.st_gid # Close the file os.close( fd) The output of executing the above program is: File info : (33261, 3753776L, 103L, 1, 0, 0, 102L, 1238783197, 1238786767, 1238786767)File UID :0File GID :0 [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Rust SliceRust Loop β†’