Python os.lstat() Method
os.lstat() Overview
The os.lstat() method is used to return information about a file similar to stat(), but without the symbolic links. On some platforms, this is an alias for fstat, such as Windows.
os.lstat() Syntax
The lstat() method syntax format is as follows.
os.lstat(path)
os.lstat() Parameters
- path – the file to return the information to.
os.lstat() Return Value
Returns the file information.
os.lstat() Demo#1
The following example demonstrates the use of the lstat() method:
#!/usr/bin/python3
import os, sys
# Open file
path = "/root/apidemos.com.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close the open file
os.close( fd )
# Get the tuple
info = os.lstat(path)
print ("File Information by os.lstat:", info)
# Get file uid
print ("File UID :%d" % info.st_uid)
# Get file gid
print ("File GID :%d" % info.st_gid)
Output: