Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.lstat() method

Python os.lstat() method

Python File methods Python 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

Return Value

Returns file information.

Example

The following example demonstrates the use of the lstat() method:


#!/usr/bin/python
# -*- coding: UTF-8 -*-

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

Python File methods Python OS file/directory methods