logo

Python Os.stat() Method


Show

Description

Python method stat() performs a stat system call on the given path.

syntax

Following is the syntax for stat() method:

os.stat(path)

Parameters

  • path − This is the path, whose stat information is required.

Return Value

Here is the list of members of the stat structure:

  • st_mode − protection bits.
  • st_ino − inode number.
  • st_dev − device.
  • st_nlink − number of hard links.
  • st_uid − user id of owner.
  • st_gid − group id of owner.
  • st_size − the size of the file, in bytes.
  • st_atime − time of most recent access.
  • st_mtime − time of most recent content modification.
  • st_ctime − time of most recent metadata change.

Example

The following example shows the usage of stat() method

# !/usr/bin/python

import os, sys

# showing stat information of file "a2.py"
statinfo = os.stat('a2.py')

print statinfo

When we run the above program, it produces the following result:

posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st
_nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498089, st_mtime=13
30498089, st_ctime=1330498089)

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.