Python3 os.lstat() Method
Python3 OS File/Directory Methods
Overview
The os.lstat() method returns information about a file like stat(), but without following symbolic links. On some platforms it is an alias for fstat, for example on Windows.
Syntax
The **lstat()** method syntax is as follows:
os.lstat(path)
Parameters
-
path -- The file whose information is returned.
Return Value
Returns file information.
Example
The following example demonstrates the use of the lstat() method:
#!/usr/bin/python3
import os, sys
# Open file
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close open files
os.close( fd )
# Get tuple
info = os.lstat(path)
print ("文件信息 :", info)
# Get file uid
print ("文件 UID :%d" % info.st_uid)
# Get file gid
print ("文件 GID :%d" % info.st_gid)
The output of the above program is:
文件信息 : (33261, 3450178L, 103L, 1, 500, 500, 0L,
1238866944, 1238866944, 1238948312)
文件 UID :500
文件 GID :500