Python | os.path.samestat() method
Last Updated :
17 Jul, 2021
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name manipulation.
os.path.samestat() method in Python is used to check whether the given stat tuples refer to the same file or not. A Stat tuple is an object that may have been returned by os.fstat(), os.lstat() or os.stat() method. It represents the status of the a path.
Syntax: os.path.samestat(stat1, stat2)
Parameter:
stat1: A stat tuple.
stat2: A stat tuple.
Return Type: This method returns a Boolean value of class bool. This method returns True if both stat tuple refer to the same file otherwise returns false.
Code : Use of os.path.samestat() method to check whether the given stat tuples refer to same file.
Python3
import os
path1 = "/home / ihritik / Desktop / file.txt"
stat1 = os.stat(path1)
path1 = "/home / ihritik / Desktop / file.txt"
fd = os. open (path1, os.O_RDONLY)
stat2 = os.fstat(fd)
sameFile = os.path.samestat(stat1, stat2)
print (sameFile)
os.close(fd)
path3 = "/home / ihritik / Desktop / file.txt"
stat3 = os.lstat(path3)
sameFile = os.path.samestat(stat1, stat3)
print (sameFile)
path4 = "/home / ihritik / Documents / file.txt"
stat4 = os.stat(path4)
sameFile = os.path.samestat(stat1, stat4)
print (sameFile)
|
Reference: https://docs.python.org/3/library/os.path.html
Share your thoughts in the comments
Please Login to comment...