Easy Tutorial
❮ Python Os Fdatasync Ref Math Asinh ❯

Python3 os.lstat() Method

Python3 OS File/Directory Methods


Overview

The os.lstat() method is used to return information about a file similar to stat(), but without following symbolic links. On some platforms, this is an alias for fstat, such as in Windows.

Syntax

The syntax for the lstat() method is as follows:

os.lstat(path)

Parameters

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 the opened file
os.close( fd )

# Get the tuple
info = os.lstat(path)

print ("File info :", info)

# Get file uid
print ("File UID  :%d" % info.st_uid)

# Get file gid
print ("File GID :%d" % info.st_gid)

Executing the above program outputs:

File info : (33261, 3450178L, 103L, 1, 500, 500, 0L, 
             1238866944, 1238866944, 1238948312)
File UID :500
File GID :500

Python3 OS File/Directory Methods

❮ Python Os Fdatasync Ref Math Asinh ❯