Sunday, August 16, 2020

Python os.stat() Method with example



Hello dear readers! Welcome back to another section of our tutorial on Python. In this tutorial guide, we are going to be studying about the Os stat() method.

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

Below is the list of members of stat structure -

  • st_dev - ID of the device containing file.
  • st_mode - protection
  • st_nlink - the number of hard links
  • st_uid - user ID of owner
  • st_gid - group ID of owner
  • st_size - total size, in bytes
  • st_atime - the time of last access
  • st_mtime - the time of last modification
  • st_ctime - time of the most recent metadata change

Syntax

The following below is the syntax for Python Os stat() method -

os.stat( path )


Parameter Details

  • path - This is the file path whose stat information is needed.

Return Value

This returns information about a file.

Example

The following below is a simple example -

# !/usr/bin/python

import os, sys

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

print statinfo

Output
When the above code is executed, it will produce 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)


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be studying about the Python OS stat_float_times() Method.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.
Share:

0 comments:

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.